git version rollback

Source: Internet
Author: User

First say the problem encountered today, see a config.php configuration file has been in the state of modification, but and remote config.php is inconsistent, I do not need to submit it, but see it in the state of modified, very uncomfortable, want to delete it, git rm config.php, and then git push, the result not only the local config.php killed, the remote config.php also to kill, the original git RM has this effect, and I delete not just this one file, there are n files.


Thought of rolling back to the last commit. Before doing this work, remind, in the local directly to the code back up a copy, or after the improper operation, will directly make your changes all erased, to the time you cry is too late; unless you have a relative grasp of git, know the meaning of any one-step operation, understand the branch mechanism of git.

Rollback is divided into three steps:

(1) Back up your current code base a copy, not the necessary action, but the reminder to do, of course, you can use Git branch backup to back up the current version to a new branch

(2) Git log find the version to roll back

(3) Git reset--hard to rollback to the version number, such as Git reset--hard 91deaf (files are back, including config.php)

Then git status may remind you that Your branch is behind ' Origin/master ' by 2 commits a similar error, and then remind you to pull down with git pulls first. If you direct git push is not going to push,
Since the remote is already on your reset version, that is, the remote version is newer than your reset version, you are reset rollback to the old version.
But after you git pull (I'm using git fetch, and then git merge merge), I'm going to re-cover the old version of the repository with the latest version of the remote, and back to the beginning of the problem.


If you find a problem and switch back to the backup branch after the three steps above, and back to the beginning of your local operation, the reset rollback file is deleted, such as config.php, which is very NB. In fact, the backup branch is your current version of the latest state, reset back to the old version.

So how do we solve the problem? A very stupid way, but there is no good way to find it.

git reset, git push-f strong push, if not with the parameter-F is not pushed.

After pushing, add the files you modified this time, git add, git commit, git push is complete.


Think: Maybe using git reset--soft will solve this problem.

git version rollback

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.