[英]How to undo a git commit and push, reset to merge
Here is my current situation.这是我目前的情况。 I merged a branch into my
live
branch and pushed it to the remote repository.我将一个分支合并到我的
live
分支并将其推送到远程存储库。 But, there was an issue with code on that branch.但是,该分支上的代码存在问题。 I want to revert this
live
back to a previous commit which happens to be another merge into the live
branch.我想将这个
live
恢复到以前的提交,这恰好是另一个合并到live
分支。 How would I do this?我该怎么做?
I don't quite understand the difference between git revert
reset
and rebase
, and am not sure which of any of these is appropriate in this case.我不太明白 git
revert
reset
和rebase
之间的区别,并且不确定这些中的哪一个适合这种情况。
don't quite understand the difference between git revert reset and rebase
不太明白 git revert reset 和 rebase 的区别
Well you could use any of them.那么你可以使用它们中的任何一个。 But because you already pushed, using revert is the only "nice" way of doing it if you have other people working on the same repo.
但是因为你已经推送了,如果你有其他人在同一个 repo 上工作,使用 revert 是唯一的“好”方法。
As for how to apply the revert:至于如何应用还原:
git revert -m 1 <merge commit hash>
Note you need the -m option because, merge commits are essentially commits with pointers to 2 parent commits and:请注意,您需要 -m 选项,因为合并提交本质上是带有指向 2 个父提交的指针的提交,并且:
"Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from 1) of the mainline and allows revert to reverse the change relative to the specified parent." “通常你不能恢复合并,因为你不知道合并的哪一侧应该被视为主线。此选项指定主线的父编号(从 1 开始),并允许恢复相对于指定的父级反转更改。 ”
https://git-scm.com/docs/git-revert#Documentation/git-revert.txt https://git-scm.com/docs/git-revert#Documentation/git-revert.txt
to revert a change you made, you can use git-revert要还原您所做的更改,您可以使用git-revert
you can use revert like this:您可以像这样使用还原:
git revert -m 1
the number 1
represent the number of commits you want to revert.数字
1
表示要还原的提交数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.