Using Visual Studio 2015, how to commit only one file?

GitVisual Studio-2015Team Explorer

Git Problem Overview


What I've tried: I don't recall to have an issue when in VS2013. When in VS2015, I've tried the context menu inside one code file or right clicking just that file from Solution Explorer, yet it includes all changed files.

I've also tried filtering and that doesn't help narrow down the checkin.

Git Solutions


Solution 1 - Git

If you're using Git with Visual Studio 2015, from Team Explorer, right-click on just the file(s) you want to commit and select Stage.

Now you'll have a new section above Changes called Staged Changes that only contain the file(s) you want. Type in your commit message and then select Commit Staged. Everything else will still be untouched under Changes.

Solution 2 - Git

OR, or, you can always do this in git bash(windows). Make sure you open git bash in your project folder and type following commands:

$ git add fileToCommit.extension
$ git commit -m "This is my commit message"

Push when you are done:

$ git push

Solution 3 - Git

I have Visual Studio 2019 Community Edition and the tab "Team Explorer" doesn't work for me so @JayAdams' answer is of no use for me. I also don't want to dabble with the command line if I can avoid it, so I found this other way:

  1. Find the 'Git Changes' tab next to the 'Solution Explorer' one.
  2. Stage only the file you want by right-clicking it and click "Stage".
  3. After doing the last step above, the button that said "Commit All" now says "Commit Staged", so you can use it now safely.

Solution 4 - Git

View->Other windows->Pending Changes

Then exclude whichever file you do not want to commit.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRyan Betker - healthNCodeView Question on Stackoverflow
Solution 1 - GitJay AdamsView Answer on Stackoverflow
Solution 2 - GitIgor PavlichenkoView Answer on Stackoverflow
Solution 3 - GitknocteView Answer on Stackoverflow
Solution 4 - GitkoninosView Answer on Stackoverflow