Home >Operation and Maintenance >Linux Operation and Maintenance >Detailed explanation of git deletion and rollback of branches
This article mainly introduces the relevant information about git deletion of branches and detailed examples of rollback. I hope that everyone can understand and master this part of the content through this article. Friends in need can refer to
git deletion Detailed examples of branches and rollbacks
[git deletes local branches]
git branch -D br
[git deletes remote branches]
git push origin :br (origin 后面有空格)
Git code base rollback: refers to returning a certain branch of the code base to a previous commit id
[Local code base rollback]:
git reset --hard commit-id :回滚到commit-id,讲commit-id之后提交的commit都去除 git reset --hard HEAD~3:将最近3次的提交回滚
[Remote code base rollback]:
This is the key point, the process is more complicated than local rollback
Application scenarios: If a problem is discovered after the automatic deployment system is released, it needs to be rolled back to a certain commit and then re-released
Principle: First return the local branch to a certain commit, delete the remote branch, and then push the local branch again
Operation steps:
1. git checkout the_branch
2. git pull
3. git branch the_branch_backup //Back up the current status of this branch Situation
4. git reset --hard the_commit_id //Roll back the_branch locally to the_commit_id
5. git push origin: the_branch //Delete remote the_branch
6 , git push origin the_branch //Re-establish the remote branch with the local branch after rollback
7. git push origin: the_branch_backup //If the previous ones are successful, delete this backup branch
[ View branch】
git branch -a
【Create local branch and push to remote】
git branch test git push origin test
The above is the detailed content of Detailed explanation of git deletion and rollback of branches. For more information, please follow other related articles on the PHP Chinese website!