How do I “reopen” a git commit?

(Note, I’m not looking for the answer git rebase -i)

In mercurial, I can “reopen” a commit by importing it into my patch queue:

  • Git: Cherry-Pick to working copy without commit
  • fatal: Unable to create temporary file '/home/username/git/myrepo.git/./objects/pack/tmp_pack_XXXXXX': Permission denied
  • How can I do a bugfix on master and integrate it into my less stable branch(es)?
  • How to make TortoiseSVN / TortoiseGit show the executed command?
  • How to let gitignore track subdirectory instances of a file while ignoring everything else?
  • Git commit asking for comment
  • hg qimport tip

    The commit is “open” in the sense that it’s just like before I had committed it, I can revert, do hg diff, hg status, etc. How do I do this in git?

    (Everything I’ve found on the web suggests git rebase -i and then choose edit, but that’s different, because the commit is not “open” in the same way.)

  • How secure is storing password with Git?
  • Git clone: “You appear to have cloned an empty repository”
  • cherry-picking with git with a conflict
  • Customising the default TFS Git build template
  • Heroku app doesn't get updated after git push heroku master
  • How should I organize my Git repositories and branches to create multiple versions of a website?
  • 4 Solutions collect form web for “How do I “reopen” a git commit?”

    You just need to move your HEAD pointer up without making any changes to your working copy:

    git reset --soft HEAD^

    Reset moves the pointer, and the soft option specifies that it shouldn’t change any of your files. The default is mixed, which will reset your index, and the hard option will actually remove the changes since that commit in your working copy.

    HEAD is a “magic” git pointer that is always pointing to the current ref (i.e. the parent of your working copy). The caret (^) indicates the parent. You can use this repeatedly, e.g. HEAD^^ refers to the parent of the last commit.

    Assuming you haven’t yet pushed to your remote repository, git reset --soft HEAD^ will “reopen” your last commit at the expense of losing your commit message.

    You can achieve the same result using git commit --amend.

    See comparison chart between Hg & Git.

    Scott Chacon has (wonderfully) elaborated about the ‘git reset’ command:
    Do not hesitate to have a look at it.

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