Revert. You can revert (or revert) a commit or a commit. After revert, the staging area creates a file that looks like it was before the specified COMMIT was changed.

Git commit link A -> B -> C -> D

Restore a COMMIT

Git revert commitId recommit a commit.

If you want to restore the last commitD commit, you can use HEAD:

git revert HEAD
git commit -m "revert D"
Copy the code

After the Git Revert HEAD is done, the mount commitD file is created as it was before the commitD changes were committed, and a new COMMIT is created.

At this point, the commit chain becomes: A -> B -> C -> D->’ REVERT D’

After the Git Revert HEAD, it is possible to simply edit the description and save it to generate a new COMMIT.

If you want to restore a specified COMMIT, such as a C commit, you can execute the following code:

git revert C
git commit -m "revert C"
Copy the code

At this point, the COMMIT chain becomes: A -> B -> C -> D->’ REVERT C’

Restore a commit

git revert -n C^.. D means to resubmit a commit. After revert, the temporary storage will create a file that looks as it did before the COMMIT was changed.

If you want to undo C and D’s submission:

git revert -n C^.. D git add -m "Revert C D"Copy the code

Git revert -n C^.. Commits of D, C, and D are uncommitted to the staging area, and the contents of the file are restored to their original state. Then a commit is executed to generate a new COMMIT to the local repository.

The commit chain looks like this:

A -> B -> C -> D-> 'Revert C D'

The difference between revert and reset

  1. While revert generates a new commit record, reset deletes the specified commit
  2. In the old branch of merge, the contents of revert are no longer included, while in reset, the contents of the old version are included.