[英]revert multiple branch merged to develop
So I have a branch named BRANCH_A
and there is another branch named BRANCH_B
which these two branchs merged to develop branch. 因此,我有一个名为BRANCH_A
的分支,还有另一个名为BRANCH_B
分支,这两个分支合并成一个分支。 Now something went wrong in BRANCH_A
, it's looks like regression for some reasons, maybe bad merged, after this merge I had few minor commits also in BRANCH_A
anyway I need to revert back BRANCH_A
to a safe commit before this merged happened. 现在, BRANCH_A
,由于某些原因,它看起来像是回归,可能合并得不好。在合并之后,我在BRANCH_A
也进行了一些次要的提交,无论如何,我需要在合并发生之前将BRANCH_A
恢复为安全的提交。 I follow other similar issues posts in stack, and did this as below : 我遵循堆栈中其他类似问题的帖子,并且如下所示:
first inside BRANCH_A
I create a backup branch : 首先在BRANCH_A
内部创建一个备份分支:
git branch BACKUP_A
Then reset to SHA from yesterday, which is a commit just before that merged happened : 然后从昨天重置为SHA,这是在合并发生之前的提交:
git reset --hard SHA
Then point the BRANCH_A
to backup branch : 然后将BRANCH_A
指向备份分支:
git reset --soft BACKUP_A
Then commit : 然后提交:
git commit -m "Revert to SHA id"
and pushed : 并推:
git push
This will revert to that commit, But the thing is, I still have other branch changes ( for BRANCH_B ) on that merge and this only revert back those minor commits that I did after merge. 这将恢复为该提交,但是问题是,在该合并中我仍然有其他分支更改(对于BRANCH_B),并且这仅恢复了我在合并后所做的那些较小的提交。
How can I revert in a way that I get raid of those changes from other Branch ( BRANCH_B ) and only keep changes that I actually did in BRANCH_A ( the commit before merge ) . 我该如何还原到其他分支(BRANCH_B)中来的更改,而仅保留我实际上在BRANCH_A中所做的更改(合并之前的提交)。
So I was able to fix this issue by doing these : 因此,我可以通过以下操作解决此问题:
Inside the branch_a that have issue : 在有问题的branch_a内部:
Git reset —hard commitID
Git merge origin/develop
Git push -f
Then checkout develop and delete the branch_a 然后结帐开发并删除branch_a
git checkout develop
git branch D branch_a
And checkout it again 然后再次结帐
git checkout branch_a
Hope it works for someone who face similar issue. 希望它对面临类似问题的人有用。
Note : Be careful when you run Git push -f
because if you made a mistake you will loose your code 注意:运行Git push -f
时要小心,因为如果输入错误,则会丢失代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.