[英]Git: Merging changes after branching before a revert
I've gotten myself into quite a tangle. 我陷入了纠结之中。
I committed a restructuring change that significantly reduced functionality to master
. 我提交了一项重组更改,大大减少了
master
功能。 (I recognise that this was a mistake.) (我认识到这是一个错误。)
This started to cause problems, because it was unfeasible to use the program with that change applied, but I had already committed further, unrelated improvements to master
. 这开始引起问题,因为在应用该更改的情况下使用该程序是不可行的,但我已经对
master
进一步的,无关的改进。
So, I reverted the restructuring change on master
, and started a new branch (say restructure
) based off the commit before the revert. 所以,我恢复了
master
的重组更改,并在恢复之前基于提交启动了一个新的分支(比如restructure
)。
The problem now is that further valuable commits have since been made to master
that I would like to pull in to restructure
to ease its development. 现在的问题是,我已经
master
了更多有价值的提交,我希望进行restructure
以简化其开发。 But git merge
tries to apply the revert of the initial restructuring — oops! 但是
git merge
尝试应用初始重组的恢复 - 哎呀!
I'm not sure what to do now, and I feel like a bad decision now could vastly complicate the merge back in to master
later on. 我不知道现在做什么,我觉得自己像现在一个错误的决定可能早在合并大大复杂化,以
master
以后。
To complicate things further, the restructure
branch has been pushed. 为了进一步复杂化,
restructure
分支已被推动。 However, I don't mind having to use git push --force
if it'll clear up all this mess; 但是,我不介意必须使用
git push --force
如果它能清除所有这些混乱; only a few people have pulled the repository since. 从那以后只有少数人拉过了存储库。
I accept that the true solution to this may fail to be an answer to the question asked — this definitely feels like an XY Problem scenario — but I had to put something in the title :) 我同意,真正的解决方案,这可能失败是一个问题的答案问-这肯定感觉就像一个XY问题情景-但我不得不把东西在标题:)
Note: I realise all this is symptomatic of a bad git workflow, and this is certainly incentive enough for me to do things more properly in the future. 注意:我意识到所有这些都是一个糟糕的git工作流程的症状,这对我来说肯定足够激励我将来做得更好。 However, I can't retroactively not have done the wrong thing, so my problem remains :)
但是,我不能追溯没有做错事,所以我的问题仍然是:)
既然你没有推入master(?),即使你也可以强制推送并重写历史记录,你可以在master中git rebase -i
并删除重组提交本身而不是恢复,然后从中创建restructure
分支掌握自己(因为你将要合并)并继续努力。
You can use git cherry-pick to pick just the commits you want over to the new branch from master. 您可以使用git cherry-pick从master中选择您想要提交到新分支的提交。 It will only bring over the changes in the hash tag specified.
它只会带来指定的哈希标记的更改。 Check out the man page for git-cherry-pick.
查看git-cherry-pick的手册页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.