How do you undo changes in Git: how do reset, revert, amend and reflog differ?
Short answer
git revert creates a new commit that undoes another, safe on shared branches. git reset moves the branch pointer back, rewriting history, so use it only on unpushed commits. If you lose a commit, git reflog almost always saves you.
3 points to say:
- Revert for shared history; reset, amend only for unpushed commits.
--softkeeps index and files,--mixed(default) resets the index,--hardoverwrites the working tree.- Reflog recovers commits until they expire and gc runs, but not uncommitted changes.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.