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: How to edit/reword a merge commit's message?
  • How can I change my git timezone offset?
  • How to commit no change and new message?
  • Undo delete in GIT
  • Get the commits made by specific authors (more than one)
  • How to combine group of local commits to single push in IDEA?
  • How to deploy a plugin to Jenkins Hosting?
  • Cloning Android sources to a local repository server
  • Deleting a remote branch
  • Should I add the google-services.json (from Firebase) to my repository?
  • Are there any good graphical Git and Hg/Mercurial clients on Mac OS X?
  • Git bash for Windows NOT prompting for password
  • 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.