Remove file from commit
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.
5 Solutions collect form web for “Remove file from commit”
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.
git rm --cached will remove it from the commit set (“un-adding” it); that sounds like what you want.
if you have already pushed your commit then. do
git checkout origin/<remote-branch> <filename> git commit --amend
AND If you have not pushed the changes on the server you can use
git reset --soft HEAD~1
Use stash; like this:
git add . git reset Files/I/Want/To/Keep git stash --keep-index git commit -a -m "Done!" git stash pop
If you accidentally commit a file, and want to rewrite your git history, use:
git reset HEAD~1 path/to/file git commit -a -m "rollback" git rebase -i HEAD~2
and squash to the two leading commits. You can write a helper script to do either of these if you have a known set of files you prefer not to automatically commit.
Maybe you could also use stash to store temporaly your modifications in a patch file and then reapply it (after a checkout to come back to the old version). This could be related to this other topic : How would I extract a single file (or changes to a file) from a git stash?.