[Git] How does git roll back the code to a commit?

Rewriting branches is too dangerous -> you need a useful tool

  • reset is not limited to rewriting history. If you want to roll the online version back to a precise commit state:
  1. Checkout history submission first
  2. Then reset mixed to HEAD and do another commit
  3. This commit contains the revert of all changes between the two.

git checkout [historical commit record] # Back to the historical version

git reset --mixed [branch] # Bring the historical version to the HEAD

git checkout [branch] # Switch back to the branch

git commit # Submit the historical version and the revert diff of HEAD

Guess you like

Origin blog.csdn.net/m0_46537958/article/details/108626893