Remove a file from the list that will be committed

Max Frai picture Max Frai · Aug 25, 2010 · Viewed 117.7k times · Source

I have a list of changed files in git repository. There is one file I don't wanna commit for the current moment. Can I do:

git commit -a

To commit all files and then somehow remove that file from current commit? After such removing it should still be in the list of uncommited files.

Answer

Cascabel picture Cascabel · Aug 25, 2010

You want to do this:

git add -u
git reset HEAD path/to/file
git commit

Be sure and do this from the top level of the repo; add -u adds changes in the current directory (recursively).

The key line tells git to reset the version of the given path in the index (the staging area for the commit) to the version from HEAD (the currently checked-out commit).

And advance warning of a gotcha for others reading this: add -u stages all modifications, but doesn't add untracked files. This is the same as what commit -a does. If you want to add untracked files too, use add . to recursively add everything.