挑选一系列的提交记录无法工作,但是单独挑选提交记录可以工作。

4
我在合并一段提交的范围时出现了问题,不断出现冲突,但我无法确定问题所在。冲突不应该发生,因为被合并的提交添加/修改的代码在接收分支中不存在。
步骤如下:
我正在合并来自名为FeatureX的分支的提交,提交看起来像这样:
>> git log --oneline

cbd0d94ca312 (HEAD -> FeatureX) Version 6
e1da344f20b7 Version 5
a9875369a8e4 Version 4
44d7975d975f Version 3
6955a667be84 Version 2
c7c70076c435 Version 1

现在,我有一个叫做MainCode的分支,我想从FeatureX分支挑选上述提交。如果我逐个挑选它们:

>>git cherry-pick c7c70076c435
[MainCode 7850ed1c4a4d] Version 1
 Date: Sat Jun 13 19:59:04 2020 -0700
 2 files changed, 321 insertions(+), 1 deletion(-)
 create mode 100644 STHelper.cs

>>git cherry-pick 6955a667be84
[MainCode df98023a9ac9] Version 2
 Date: Tue Jun 16 15:36:24 2020 -0700
 1 file changed, 68 insertions(+), 15 deletions(-)

>>git cherry-pick 44d7975d975f
[MainCode beede732db3f] Version 3
 Date: Tue Jun 23 14:34:27 2020 -0700
 1 file changed, 104 insertions(+), 23 deletions(-)

>>git cherry-pick a9875369a8e4
[MainCode 77664b1d36c2] Version 4
 Date: Wed Jul 8 21:25:27 2020 -0700
 1 file changed, 25 insertions(+), 15 deletions(-)

>>git cherry-pick e1da344f20b7
[MainCode 8eb1c3cf9828] Version 5
 Date: Fri Jul 10 03:39:47 2020 -0700
 1 file changed, 67 insertions(+), 19 deletions(-)

>>git cherry-pick cbd0d94ca312
[MainCode a07e9f4dbed9] Version 6
 Date: Fri Jul 10 14:28:10 2020 -0700
 3 files changed, 174 insertions(+), 35 deletions(-)
 create mode 100644 config_debug.xml

如果我只是单独挑选它们,它们都可以正常工作。但如果我试图将它们一起挑选...

>>git cherry-pick c7c70076c435^..cbd0d94ca312
error: could not apply 6955a667be84... Version 2
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

>>git status
On branch MainCode
Cherry-pick currently in progress.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
        deleted by us:   STHelper.cs

no changes added to commit (use "git add" and/or "git commit -a")

... 有冲突。 我还尝试使用 他们的 更改(即来自 FeatureX 分支的更改)来解决冲突 ...

>>git cherry-pick c7c70076c435^..cbd0d94ca312 --strategy=recursive -X theirs
error: could not apply 6955a667be84... Version 2
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

......但它仍然不起作用。

有人能告诉我问题在哪里吗?

[编辑] 我正在使用Windows的cmd.exe作为shell。


1
git log --oneline c7c70076c435^..cbd0d94ca312 命令输出的相关提交是否与 git log --oneline 命令输出的提交顺序相同? - ElpieKay
这可能是一个shell问题:如果你正在使用的shell从命令行中吞掉了 ^,那么第一个提交将被跳过。 - LeGEC
@ElpieKay,如果我在“Feature X”分支上运行您提供的命令,则会得到与我在帖子中提到的相同的提交顺序。唯一的区别是该列表中没有提到第一个提交(哈希为c7c70076c435)。 - Ahmad
2
尝试使用 echo a^b 命令,你会发现问题所在,^ 字符是 cmd 使用的转义字符之一,因此它将被剥离。请尝试使用 ~1 代替。 - Lasse V. Karlsen
引用范围是否可行?尝试使用git log --oneline 'c7c70076c435^..cbd0d94ca312'命令(在范围周围加上单引号)查看第一个提交是否出现。或者从git-bash运行您的命令。 - LeGEC
显示剩余3条评论
1个回答

6

这是一个关于shell的问题:正如评论中所述,您正在使用cmd.exe,其中^是一个转义字符(例如,请参阅此链接:Windows命令行中的转义字符)。

您的输入字符串:

c7c70076c435^..cbd0d94ca312

被转换为:

c7c70076c435..cbd0d94ca312

第一次提交会被跳过。


如果你使用cmd.exe:像@LasseVKarlsen建议的那样使用~1或者使用^^代替普通的^

git cherry-pick c7c70076c435^^..cbd0d94ca312

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接