How to roll back the latest version of Git to the specified version number and create a new branch for the specified version to synchronize to the remote warehouse

How to roll back the latest version of Git to the specified version number and create a new branch for the specified version to synchronize to the remote warehouse

    When we use the Git distributed management tool, we often involve how to switch the latest local code to the specified version in the previous version history (here may be code bugs, requirements changes, version branches, product line branches, etc.), This is a problem I have encountered in actual development, so I will record the entire operation process here, so that it can be used directly next time, instead of going to Baidu to rummage, and the things that Baidu arrives are not necessarily correct , you must choose according to your own problems, otherwise you will always regret it. I remember that once I messed up the entire local version library directly, which caused me to re-write a code. I won’t gossip and go directly to the operation steps. :

1. First re-clone the latest remote code to another file directory (to avoid file project name conflicts).

93287@DESKTOP-0413I27 MINGW64 /d/workspaceMaster-DongNaoVip2018-04-09
$ git clone https://gitee.com/qrmc/his_pay.git
Cloning into 'his_pay'...
remote: Counting objects: 4154, done.
remote: Compressing objects: 100% (3254/3254), done.
remote: Total 4154 (delta 2066), reused 150 (delta 28)
Receiving objects: 100% (4154/4154), 4.12 MiB | 1.12 MiB/s, done.
Resolving deltas: 100% (2066/2066), done.

2. Roll back the current version of the new project to the historical version node (here you can choose to roll back according to the description when you submitted the code, so try to write the description of the submitted code as clearly as possible during development to facilitate the rollback of future versions) , the version number to be rolled back here: e29440fbf364ca29656e42769d342c34b279bbc9, you only need to fill in the first 6 digits (e29440) to roll back the version when rolling back.

93287@DESKTOP-0413I27 MINGW64 /d/workspaceMaster-DongNaoVip2018-04-09/his_pay (master)
$ git checkout e29440
Note: checking out 'e29440'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at e29440f... 分界线=======分布式事务处理

3. Create a new branch (e29440) to keep the switched version branch.

93287@DESKTOP-0413I27 MINGW64 /d/workspaceMaster-DongNaoVip2018-04-09/his_pay ((e29440f...))
$ git checkout -b e29440
Switched to a new branch 'e29440'

4. Check the local branch, the current one is: e29440.

93287@DESKTOP-0413I27 MINGW64 /d/workspaceMaster-DongNaoVip2018-04-09/his_pay (e29440)
$ git branch 
* e29440
  master

5. View the remote branch status, currently: master.

93287@DESKTOP-0413I27 MINGW64 /d/workspaceMaster-DongNaoVip2018-04-09/his_pay (e29440)
$ git branch -r
  origin/HEAD -> origin/master
  origin/master

6. Create a new branch (branch name: e29440) in the remote warehouse, and submit the current local branch (e29440) to the remote branch. At this time, you can see the branch and the project corresponding to the branch in the remote warehouse.

93287@DESKTOP-0413I27 MINGW64 /d/workspaceMaster-DongNaoVip2018-04-09/his_pay (e29440)
$ git push origin e29440
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by Gitee.com
To https://gitee.com/qrmc/his_pay.git
 * [new branch]      e29440 -> e29440

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325255860&siteId=291194637