【发布时间】:2015-07-20 14:37:48
【问题描述】:
我有一个正在使用 git 管理的项目。
我希望每次提交都能干净地应用到以前的历史记录,因为提交补丁是由 git 本身生成的。
如果我有
------tagA--commit_A1--commit_A2--commit_A3
\
\[branch A]
\
\-commit_A'1--commit_A'2--commit_A'3--commit_A'4
我在分支A,它源于tagA。
证实了这一点git merge-base A tagA
返回 tagA 的提交 sha。我试图发出
git rebase tagA
变基行为应该是:
- 倒回tagA
- 将所有来自tagA的提交应用到branchA的尖端,即应用commit_A'1、commit_A'2、commit_A'3、commit_A'4
该过程应该让我回到 branch_A 的尖端而不做任何更改。
相反,我在其中一个提交中遇到了冲突。
示例
# git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git GIT_linux
# cd GIT_linux
# git remote add linux-at91 https://github.com/linux4sam/linux-at91.git
# git fetch linux-at91
# git checkout -b linux-3.10-at91 linux-at91/linux-3.10-at91
# git rebase v3.10
First, rewinding head to replay your work on top of it...
Applying: dmaengine: at_hdmac/trivial: correct typo in comment
Applying: dmaengine: at_hdmac: extend hardware handshaking interface identification
Applying: dmaengine: at_hdmac/trivial: rearrange CFG register bits assignment
Applying: DMA: AT91: Get transfer width
Applying: DMA: AT91: Get residual bytes in dma buffer
Applying: dma: use platform_{get,set}_drvdata()
Applying: dma: mxs-dma: Staticize mxs_dma_xlate
Applying: dma: at_hdmac: remove unnecessary platform_set_drvdata()
Applying: dma: timb_dma: remove unnecessary platform_set_drvdata()
Applying: dw_dmac: remove inline marking of EXPORT_SYMBOL functions
Applying: dma: tegra20-apbdma: err message correction
Applying: dma: tegra: avoid channel lock up after free
Applying: dmaengine: sirf: set dma residue based on the current dma transfer position
Applying: dma: of: Remove restriction that #dma-cells can't be 0
Applying: dma: of: Remove check on always true condition
Applying: dma: of: Remove restriction that #dma-cells can't be 0
Using index info to reconstruct a base tree...
M drivers/dma/of-dma.c
Falling back to patching base and 3-way merge...
Auto-merging drivers/dma/of-dma.c
CONFLICT (content): Merge conflict in drivers/dma/of-dma.c
Failed to merge in the changes.
发生这种情况有什么原因吗?我的存储库是否以某种方式损坏?
rebase 不起作用,merge 起作用...
我尝试了相反的方法,我可以做到这一点
git checkout -b my3.10.84 v3.10.84
git merge linux-at91/linux-3.10-at91
这导致只有几个冲突的文件,我修复并提交了这些文件。
【问题讨论】:
-
“有什么原因……?”是的。在
linux-at91/linux-3.10-at91的原始合并基础和标签v3.10之间的提交中,对文件drivers/dma/of-dma.c的更改与"dma: of: Remove restriction that #dma-cells can't be 0"提交中对git rebase当前所在的同一文件所做的更改相冲突试图处理。使用git log -p <original merge base>..v3.10调查... -
也许提交首先导致冲突解决,但不应该将更正(即非冲突)提交最终记录为最终补丁吗?
-
@twalberg 问题是,
git merge-base linux-at91/linux-3.10-at91 v3.10返回v3.10commit-id。 -
提交本身通常不会导致冲突。通常只有在合并或变基时才会看到冲突。合并冲突的发生是因为两个(或多个)分支以不同的方式修改了同一段代码。重新定位冲突的发生是因为在重新定位提交之前代码段的原像与最初提交时不同,这会导致差异/补丁循环失败。
-
我试过你上面的场景。看来问题可能是由于您尝试变基的提交集包含合并。运行
git rebase -p v3.10成功。我的猜测是您遇到的冲突是在其中一次合并中解决的冲突,但是由于默认情况下git rebase不会尝试保留合并,因此您遇到了相同的冲突(并且可能还会看到其他冲突) ,如果你解决了那个)...
标签: git version-control rebase