受污染的远程主分支或反樱桃拾取 [英] Contaminated Remote master branch or Anti-Cherry-Pick
问题描述
我遇到一种情况,即远程存储库中有一些错误"的提交. 例如
I have a situation where the remote repository has some "bad" commits. e.g.
... o ---- C ---- A ---- B origin/master
A不好(B很好)的地方 我希望遥控器成为...
Where A is bad (but B is good) I want the remote to become...
... o ---- C ---- B origin/master
\
A origin/dev
我不知道该怎么做.
如果重新设置不合适,则需要不同的结果.
In the case where a rebase is inappropriate a different result is needed.
... o ---- C ---- A ---- B ---- ~A origin/master
\
- origin/dev
这将导致包含A提交的dev分支和不包含A提交的master分支. 修改后的问题是: 怎么做抗樱桃采摘? 因此,与其生成将存储库从状态C更改为A的补丁,不如应用将B更改为A的补丁.
This results in a dev branch containing the A commit and the master not containing the A commit. The revised question is: How to do an anti-cherry-pick? So rather than generating a patch which changes the repository from state C to A apply a patch which changes B to A.
推荐答案
拉动,以便您在本地拥有相同的存储库.
Pull so that you have the same repository locally.
使用git rebase --interactive
(请参见
Use git rebase --interactive
(see this rundown if you are unfamiliar with interactive rebase) to reorder the A and B commits, so that you now have
... o ---- o ---- B ---- A master
从该地点签出一个新的分支机构开发人员,这样您就可以
Checkout a new branch dev from that spot, so you get
... o ---- o ---- B ---- A master, dev
切换到master分支,执行git reset --hard HEAD^
来回退该分支一次提交.您现在有
Switch to the master branch, do a git reset --hard HEAD^
to rewind that branch one commit. You now have
... o ---- o ---- B master
\
A dev
现在git push --force --all
,您应该会变得很黄金. (您需要--force
,因为您要在远程存储库中重写历史记录,这很危险,因此如果其他开发人员已经从中撤出,则不建议这样做.)
Now git push --force --all
and you should be golden. (You need --force
because you are rewriting history in the remote repository, which is dangerous and not recommended if other developers have already pulled from it.)
这篇关于受污染的远程主分支或反樱桃拾取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!