我偶然通过Github PR将分支合并到master
。我立即恢复它(通过github)。几天之后,当代码被测试并准备合并时,合并和PR实际上不会将代码转换为master,因为提交已经存在于github中(但是代码没有,因为它已被还原。
所以现在我试图在经过一周的无关提交后,将这些更改恢复为主。这大致是git log --oneline
输出的相关点的一些评论:
54c73ee (HEAD, origin/master, origin/HEAD, staging) Merge pull request #637 from leonsas/last-night-view-metric-ceiling
...
More unrelated changes that should stay in.
...
af602f0 Merge pull request #639 from leonsas/staging
67ded36 (origin/staging) Merge <-- Here's where I tried merging the changes again, but it doesn't make it into the codebase.
...
Bunch of unrelated commits that should stay.
...
a603d0b Merge pull request #633 from leonsas/revert-628-hr-hrv-audit
c3da670 (origin/revert-628-hr-hrv-audit) Revert "Hr hrv audit"
01f2fab Merge pull request #632 from leonsas/revert-629-always-get-hrvz
5824fc8 (origin/revert-629-always-get-hrvz) Revert "Always get hrvz" <-- I reverted changes, because code wasn't tested
b75a537 First iteration at setting the max value on the chart
6939035 Merge pull request #631 from leonsas/is-valid-fix
87b53d5 Merge pull request #629 from leonsas/always-get-hrvz <-- These changes I want in
5b9a848 Merge pull request #628 from leonsas/hr-hrv-audit
将这些更改重新应用到master中的最佳方法是什么?
- 更新1
根据Thomas的建议,我再次尝试了rebase解决方案:
> git checkout -b hrv-almost-latest-changes e1d0d7b
> git rebase master-clone
First, rewinding head to replay your work on top of it...
Fast-forwarded hrv-almost-latest-changes to master-clone.
> git push --set-upstream origin hrv-almost-latest-changes
但是master
与hrv-almost-latest-changes
完全一致,所以没有什么可以合并到github PR上。
- 更新2
一般来说,樱桃采摘工作正常。具体解决方案是:
git checkout master
git checkout -b hrv-merge-fix
git cherry-pick -m 1 87b53d5
(solve conflicts)
git add <files from solved conflicts>
git cherry-pick --continue
git cherry-pick -m 1 5b9a848
git push origin hrv-merge-fix
答案 0 :(得分:0)
问题是PR包含已经是当前主人的祖先的提交:
A- ... -F--G--H- ... -I
\ / |
B--C--D--E revert PR |
| current master
| merge PR
old master |
original PR
由于B-E是我的祖先,尝试将E合并到I中并不会改变任何东西。
但是,您可以将PR分支重新绑定到当前主服务器上,以创建一个新的提交字符串,这些提交不是I的祖先,并且仍然保留这些更改:
A- ... -F--G--H- ... -I
\ / \
B--C--D--E B'--C'--D'--E'
| |
master new PR branch
现在,合并E&#39;进入我将应用这些变化。
基本上,这样做:
$ git fetch
$ git checkout E
$ git checkout -b new-pr-branch
$ git rebase master
$ git push --set-upstream origin new-pr-branch
然后从new-pr-branch
提交新的PR。
答案 1 :(得分:0)
我不太熟悉github在“幕后”所做的事情,所以我会在命令行的本地存储库中继续这样做。
您应该可以使用git checkout master ; git cherry-pick -m X 87b53d5
。有关git help cherry-pick
的价值,请参阅X
:
-m parent-number, --mainline parent-number
Usually you cannot cherry-pick 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 cherry-pick to
replay the change relative to the specified parent.