Home > Operation and Maintenance > Linux Operation and Maintenance > Detailed explanation of git deletion and rollback of branches

Detailed explanation of git deletion and rollback of branches

巴扎黑
Release: 2017-09-02 11:48:29
Original
1937 people have browsed it

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
Copy after login

[git deletes remote branches]


git push origin :br (origin 后面有空格)
Copy after login

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次的提交回滚
Copy after login

[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
Copy after login

【Create local branch and push to remote】


git branch test

git push origin test
Copy after login

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template