I have several commits already and I need to undo the latest one but to have changes I made in it in place. Please advice how to do that. Thank you.
git reset --soft HEAD^
Note that you should only rewind HEAD if it's not pushed yet.
edit In response to your comment on the original question:
If you only want to edit the most recent commit, Git has a neat feature commit --amend. Simply use git add/git rm/git checkout until your index is in the state you want it to be (new changes added, some changes thrown away, files removed, …). Then use git commit --amend, it will pop up vi (or whatever you have configured in core.editor) with your last commit's commit message for you to edit.
Note, that when I say ›edit the most recent commit‹, Git actually creates a new commit. So don't do it, when the commit was already pulled from other people (i.e. pushed to your public repository)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With