Visual Studio Git - is there a setting to prevent committing unstaged files

Viewed 3108

In Visual Studio Code there is a warning if you attempt a commit with no staged files. It warns you that it will commit all unstaged files first and then commits them.

Is there a similar setting or a way to do the same thing in Visual Studio (2017 and onwards)?

The default behavior of Visual Studio 2017, when you hit Commit without staging files first is to silently commit all unstaged files, which causes issues quite frequently (accidental commits).

Under Settings => Source Controll I only see "Plugin Selection" with no additional options.

2 Answers

I accidentally clicked on "Always" when asked if I want to commit the unstaged files.

I started looking for a way to undo that choice of "Always", so I found this thread.

Anyways, here is the solution: look for "Git: Enable Smart Commit" in the VSCode settings and uncheck it (set to false) vs code git smart commit - always commit unstaged changes

2019: There are no settings in Visual Studio, as discussed in this VSCode issue

In the case of Visual Studio, when there are no staged changes, but some changes, the content of the commit button comes "Commit All". So, user can know all changes will be committed even no changes staged.

The latest 2019 release notes don't show any evolution on that front, so for now, there seems to be no setting in place (like the one in VSCode)

That seems a bug though, considering the documentation:

Git does not automatically add changed files to the snapshot when you create a commit.
You must first stage your changes to let Git know which updates you want to add to the next commit. Staging lets you to selectively add files to a commit while excluding changes made in other files.


However, the same issue 15613 refers to VSCode 1.13 commit b31c1e1, which shows:

            if (pick === always) {
                config.update('enableSmartCommit', true, true);
            } else if (pick !== yes) {
                return false; // do not commit on cancel

So, as shown in Aleksandar's answer, enabling smart commit can help.

Only problem: issues 91472 and issues 51721: you need to avoid staging files when a commit is in progress.

Related