9

I'm working with an application that is stored on Github. I'd like to commit a single file. It seems like this would be trivial but I don't see how it's done.

If I right click on the file I want to commit and select the Commit command, it seems to show that all modified files will be checked in. There is a Commit All button/dropdown that becomes enabled when I start entering a commit message. But the dropdown has no option to commit less than everything.

enter image description here

Surely this is supported.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
  • Note that you're still committing *many* (really, all!) files: you're just making sure that the new commit has only one *different* file, when compared to the previous commit. – torek Dec 12 '18 at 19:16

1 Answers1

16

If you don't want to commit all changed files, you will need to stage the file(s) you want to commit by right-clicking the file under your list of changes and clicking Stage. After you stage some files, the button that says Commit All will change to read Commit Staged.

Sander
  • 526
  • 4
  • 10
  • 1
    Yeah, that works. Seems funky to me though. Why not just let me select the files I don't want to include in the commit? Oh well... – Jonathan Wood Dec 12 '18 at 18:48
  • 2
    Probably because the git CLI works the same way. By default, you have to stage your files with `git add` before you can commit them. If you want to commit all modified files, instead of staging them all and then committing there is also the option to `git commit --all`. The same options are available in the Visual Studio GUI. There is no direct way using the git CLI to "commit all files except x, y, and z" that doesn't involve staging and then committing as separate steps that I'm aware of. – Sander Dec 12 '18 at 18:57
  • @Sander I think you can commit a single file. See [here](https://stackoverflow.com/questions/8795097/how-to-git-commit-a-single-file-directory) for example. – Roald May 07 '19 at 06:59