Although I use Git pretty often, I\'m still a beginner.
Sometimes, I make a mistake but spot it only after I have committed it. At that point, I usually hav
Undoing Changes: git checkout
, git revert
, git reset
, git clean
git revert
: This command reverts the changes of a commit. it maintains track record in logs.
git reset
: This command reverts the changes of a commit. it does not maintain track record in logs i.e. reset to the reverted commit. Note: It an destructive function. have to be careful using this command.
git reset --soft HEAD^
Undo last commit, put changes into staging
git reset --hard HEAD^
Undo last commit and all changes
git reset --hard HEAD^^
Undo last 2 commits and all changes
git commit --amend
where amend means add to the last commit. Sometimes we forgot to add files to commit. for example abc.txt file was forgot, we can add as follows: git add abc.txt
and git commit --amend -m "New commit message"
Note: we don't have rollback and undo on this exact name either verbs or option.