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

4

61

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.

Xenomorphic answered 4/5, 2016 at 13:38 Comment(1)
Ryan you might consider either retagging this as TFS instead of git or change the accepted answer to the one posted below by Jay Adams.Violet
T
-7
View->Other windows->Pending Changes

Then exclude whichever file you do not want to commit.

Taxable answered 4/5, 2016 at 13:43 Comment(3)
Thanks.. the window slipped my mind, and have used it for years, whew.Xenomorphic
I tried that, but it doesn't work for me. I have 2 files checked out on Git (and it shows that on the regular checkin window) but when I go to "Pending Changes" it gives me a warning about "TFS is not your source control" (correct, i'm using git) but then doesn't show me any files. Any thing I need to do?Teacake
looks like you should delete this answer?Ciera
S
184

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.

Sharondasharos answered 6/9, 2016 at 15:56 Comment(6)
Considering the question is tagged as git, I think this definitely should be the accepted answer.Instant
This answer actually resolved my query and this should have been choosen as the right answerDaimon
This command is helpfully called "Stufe" (=step, in stairs) in the German version of VS 2015.Trumpery
@Trumpery That's why I gave up on localized systems shortly after I started with computers: The idiosyncrasies introduced by the translators are annoying at best, and they force you to actually learn the jargon twice. Once international (=english), and once translated (with whatever idiosyncrasies the translators came up with). I always feel lost when I see a computer that's localized to my native language...Adele
@cmaster Yeah, "Stufe" feels plain wrong in this context.Trumpery
my version of Visual/Code doesn't have a Team Explorer. Also, this reply doesn't answer the question because committing staged commits ALL staged, not just a single fileSaccharoid
J
4

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
Jaddo answered 4/5, 2016 at 13:51 Comment(1)
no, doing so you add the new file, but you commit ALL files. to commit only some files see at: #8795597Snubnosed
C
0

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.
Ciera answered 28/7, 2021 at 5:55 Comment(0)
T
-7
View->Other windows->Pending Changes

Then exclude whichever file you do not want to commit.

Taxable answered 4/5, 2016 at 13:43 Comment(3)
Thanks.. the window slipped my mind, and have used it for years, whew.Xenomorphic
I tried that, but it doesn't work for me. I have 2 files checked out on Git (and it shows that on the regular checkin window) but when I go to "Pending Changes" it gives me a warning about "TFS is not your source control" (correct, i'm using git) but then doesn't show me any files. Any thing I need to do?Teacake
looks like you should delete this answer?Ciera

© 2022 - 2025 — McMap. All rights reserved.