git version rollback: revert and reset

Source: Internet
Author: User
Tags commit reset rollback using git

When using Git, the version is often rolled back if the error is push.
There are two ways to roll back a git: revert command

git revert version ID:
This command can be used to roll back the changes made to the specified version with a reverse commit. Then you can update the code on the Git push line.
When you use Git revert, you encounter a problem. For the code submitted by the merge, the following error occurs:

Commit XXX is a merge but no-m option was given.

For the merge score, if you want to revert, you need to make a rollback to which version, because the merge design to two versions:
Such as:

Merge branch ' Rms-develop ' into master

To roll back this situation, you can use the

git revert version id-m 1

This 1 refers to the master,2 refers to the develop. It is now part of the code that rolls back the develop merge to master on the master branch.
In this way, it is resubmitted once with a reverse push. You can see the action record in Git. two reset

This command is a reset, and the error is submitted. I want to delete this commit record. Rollback can also be implemented. Comparison of two commands:

Seemingly achieve the same effect, in fact, completely different.
First:
What we said above. If you have already push to the online code base, reset deletes the specified commit, and your git push can cause a lot of conflicts. But revert doesn't.
Second:
If the existing branch and historical branches need to be merged at a later time, the code for the Reset recovery section will still appear in the history branch. However, the commit committed by the revert direction does not appear in the history branch.
Third:
Reset is in the normal commit history, the deletion of the specified commit, when the head is moved backwards, and revert is in the normal commit history to commit again, but is a reverse submission, his HEAD is always forward.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.