git revert use in remote code and rollback process

Use of revert

Use git revert undo some operations, commit and history are preserved before and after the operation, and the revocation
as the latest submitted once.

git revert HEAD    # 撤销前一次的 commit 
git revert HEAD^ # 撤销前前一次的 commit
git revert commitid # 撤销指定的版本

git revert is to submit a new version, you need to re-reversed version of the content revert back modified version is incremented, to be submitted before the content is not affected.

The difference between git revert and git reset the

  1. git revert a previous commit by a new commit to roll back, git reset directly delete the specified commit.
  2. In this rollback operation point of view, the effect is the same. But there are differences in future continue to merge before the old version. Because git revert with a reverse commit prior to the filing "and" so when the future consolidation of the old branch, resulting in this part of the changes will not occur again, but is among the git reset delete some commit on a branch , and thus when the old branch merge again, these are rolled back commit should also be introduced.
  3. git reset HEAD is to move back a bit, but git revert HEAD is to go ahead and commit just the content of the new content and revert to the contrary, be content to be able to offset the revert.

Reprinted from: https://www.cnblogs.com/0616--ataozhijia/p/3709917.html
https://github.com/geeeeeeeeek/git-recipes/wiki/5.2- Code rollback: Reset, Checkout, Revert -s Choice

git Code rollback

git repositories rollback, the code refers to the return of a branch to a previous commit id.

Native code rollback

git reset --hard commit-id  # 回滚到 commit-id 意思是commit-id之后提交的commit都去除
git reset --hard HEAD~3 # 将最近3次的提交回滚 

Remote Code rollback process

Scenario: automatic discovery of the problem after deployment, we need to roll back to a particular commit, and then republish.
Principle: The local branch will now retreated to a commit, remote branch delete and re-push local branch.
Steps:

1.  git checkout the_branch   # 切换到这个分支
2. git pull  # 拉取
3. git branch the_branch_backup # 备份一下这个分支当前的情况 
4. git reset --hard the_commit_id # 把the_branch本地回滚到the_commit_id
5.git push origin :the_branch # 删除远程分支the_branch
6.git push origin the_branch:the_branch # 使用回滚之后的分支重新建立远程分支
7. git push origin :the_branch_backup # 如果前面的都成功了 删除这个分支 

Guess you like

Origin blog.csdn.net/Enjolras_fuu/article/details/95043957