In Visual Studio Team Explorer, I can see that I have 10 changes waiting. I want to make a change to one of those files, so I write a commit description, click the Stage button … hang on, I’ve forgotten to stage that one file. Now everything has been staged!
I can see that I’m not the only person that has had this problem - apparently this is also the default behaviour in VSCode. On https://github.com/Microsoft/vscode/issues/15613 atoklen said “I would definitely like a setting to disable that, please.” and 9 others like his comment.
The good news is that if you do make this mistake and realise before you push, it’s quite easy to clean up.
Before you start, make a copy of your commit message somewhere.
From Team Explorer > Actions
Select Open Command Prompt
Type “git log -n 2” and press enter. This will show your last two commit messages, hopefully that will be the one that you want to remove, and your last successful, intended commit.
Type “git reset –soft HEAD~1” and press enter.
Now type “git log -n 2” and press enter again. The commit you wanted to remove should be gone, and it should display the last two commit messages of which both should be succesful and intended commits.
When you go back to Visual Studio Team Explorer, all of the files that you had committed will be staged. Unstage all the files you didn’t want to commit, write a commit message, and now you are ready to commit.