git creates branches and pushes them to remote branches and rolls back the code to the specified version

I. Introduction

Since the online function needs to be rolled back, so I can only helplessly roll back the code. The following is a detailed record of the rollback code for reference

Second, the specific steps

1. Create a new local branch (back up before rolling back the code):

You must choose to enter the pre-master branch before you can create another branch on his basis

$ git checkout -b pre-master-1223  // 新建本地为pre-master-1223的分支并切换至pre-master-1223分支

You can enter the ls command to continue to view the directory files under this branch

2. Check the current local branch status :

$ git branch
* pre-master-1223
  master
  export_1223

3. Create a new branch and push to the remote

Push the newly created local branch to the remote server. The remote branch has the same name as the local branch (of course you can name it at will):

$ git push origin pre-master-1223:pre-master-1223  //将本地pre-master-1223分支推送至远程pre-master-1223分支

Use git branch -a to view all branches, you will see the remote branch pre-master-1223, indicating that the new remote branch is successful.

4. Delete the remote branch

$ git push origin --delete pre-master-1223

Use the command git branch -a again to find that the remote branch pre-master-1223 has been deleted.

5. Roll back to the specified version

git reset --hard e377f60e28c8b84158(版本号)

6. Force push to remote branch

Forced to commit, roll back the local code pushed to the remote repository, where the system options need to be strengthened -for --force;

git push -f origin pre-master

Here we need to explain that git push -f means to force the current local code base to be pushed to the remote end and overwrite it; this command needs to be negotiated with team members and used carefully!

Guess you like

Origin blog.csdn.net/weixin_45811256/article/details/111687569
Recommended