What are the differences between 'revert', 'amend,' 'rollback', and 'undo' a commit?

后端 未结 3 591
[愿得一人]
[愿得一人] 2020-12-08 05:22

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

3条回答
  •  既然无缘
    2020-12-08 05:43

    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.

提交回复
热议问题