I accidentally amended my previous commit. The commit should have been separate to keep history of the changes I made to a particular file.
Is there a way to undo that last commit? If I do something like git reset --hard HEAD^
, the first commit also is undone.
(I have not yet pushed to any remote directories)
Best Answer
What you need to do is to create a new commit with the same details as the current
HEAD
commit, but with the parent as the previous version ofHEAD
.git reset --soft
will move the branch pointer so that the next commit happens on top of a different commit from where the current branch head is now.