Remove file from commit

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.

  • Git: send-email without commit
  • Git: How can I find a commit that most closely matches a directory?
  • git filter branch fatal revision
  • Git Commit during Git Rebase - what really happens?
  • git: How to get the latest commit on a specific file, regardless of branch?
  • Trouble with first commit to git repository
  • “Could not get advertised Ref for branch…” error when pulling in a git repository in Eclipse
  • How can I combine these git commands?
  • Specify an SSH key for git push for a given domain
  • git p4 clone has no files
  • gitignore for App-engine connected android project
  • Push git alias to remote repo
  • 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?.

    Git Baby is a git and github fan, let's start git clone.