Difference between HEAD^ and HEAD~
What's the difference in git between HEAD^ and HEAD~ ?
specially in these two commands:
git reset --soft HEAD~
git reset HEAD^
Also, what would be the best way to undo a commit and what would be the best way to undo a commit and a push ?
1 Reply
Following replies here: https://stackoverflow.com/questions/2221658/whats-the-difference-between-head-and-head-in-git
The symbols themselves mean the same, to refer to the parent of a commit, the difference comes in numbering (ex: A^2 A~2), because you traverse the commit history differently depending of which symbol you use.
I suggest you to jump in the replies of the StackOverflow question as they have a nice set of diagrams to explore and read.
Specially:
https://stackoverflow.com/a/23714994/13169707
and
https://stackoverflow.com/a/12527561/13169707
But seems like, from my understanding, that to undo specifically one commit, they do exactly the same thing.
I think the best way to do it would rather be using
git revert <commit hash>
which creates a new commit with the reverted changes, which you can push. This creates a messier history but you can like, fall back in case something weird happening during the revert.