Git version rollback, git version

Source: Internet
Author: User

Git version rollback, git version

Let's talk about the problem encountered today. We can see a config. the php configuration file is always in the modified state, but with the remote config. php is inconsistent. I don't need to submit it, but it is uncomfortable to see it in the modified status. To delete it, git rm config. php, and then git pushes it down, the result is not only the local config. php is killed, and the remote config. php has also been killed. It turns out that this git rm has this effect, and I deleted not only this file, but also n files.


Think of rolling back to the latest submission. Before doing this, I would like to remind you to back up the code locally. Otherwise, your modifications will be wiped out without any improper operations, and you will be too late to cry; unless you are relatively familiar with git, know the meaning of any step, and understand the git branch mechanism.

Rollback is divided into three steps:

(1) Back up your current code library, which is not a required operation, but reminds you to do so. Of course, you can use git branch backup to back up the current version to a new branch.

(2) Find the version to be rolled back in git log

(3) git reset -- hard indicates the version number to be rolled back to, for example, git reset -- hard 91 deaf (all files are returned, including config. php)

 

Then, when git status is running, you may be reminded that Your branch is behind 'origin/master' by 2 commits is similar, and then you will be reminded to use git pull to pull down first. If you cannot push git push directly,
Because the remote version is already after your reset, that is to say, the remote version is newer than your reset version, and you are the reset to roll back to the old version.
However, after you use git pull (I use git fetch, and then merge git merge), you will overwrite the local old version with the latest remote version, in this way, the problem at the beginning is returned.


If you find any problem after the above three steps of rollback, switch back to the backup branch and return to the version at the beginning of your local operation, that is, the file rolled back by the reset is deleted again, such as config. php, this is NB. In fact, the backup branch is your latest version, and the reset is back to the old version.

 

So how can we solve the problem? A very stupid method is used, but no good method is found at present.

After git reset, git push-f is strongly pushed. If-f is not included, it cannot be pushed.

After pushing, add the files you modified one by one. git add, git commit, and git push are complete.


Thinking: Maybe git reset -- soft will solve this problem.

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.