小调:不要这样做:
git cherry-pick $(git show-ref branch-a)
git cherry-pick branch-a
cherry pick命令接受标识修订,甚至是修订范围的任何内容,如中所述。
the gitrevisions documentation
git show-ref
命令输出两个哈希ID
git cherry-pick
解决冲突没有唯一正确的方法。你可以用你喜欢的任何东西。这里有几个重要的事情要记住:
-
git merge
除此之外,Git没有找到实际的合并基,而是使用您挑选的提交的父级作为合并基(当然,最终提交是常规的非合并提交)。
-
git diff
命令:
git diff --find-renames <merge-base> HEAD # figure out what we did
git diff --find-renames <merge-base> <other> # figure out what they did
git status
命令将这些显示为“未合并”,但您可以使用
git ls-files --stage
-
此时,您的工作只是在索引中排列您希望在最终提交时由于合并(在本例中是cherry-pick)而生成的文件。这些文件需要在第0阶段,也就是索引中正常的、没有冲突的文件所在的阶段。阶段1中的任何条目表示合并基中文件的版本,阶段2中的任何条目表示
HEAD
冲突本身
git diff --find-renames
branch-a
.因此,其母公司
branch-a^
$ git diff --find-renames branch-a^ HEAD
diff --git a/myFooFile b/myBarFile
similarity index 100%
rename from myFooFile
rename to myBarFile
$ git diff --find-renames branch-a^ branch-a
diff --git a/myBarFile b/myBarFile
new file mode 100644
index 0000000..5716ca5
--- /dev/null
+++ b/myBarFile
@@ -0,0 +1 @@
+bar
diff --git a/myFooFile b/myFooFile
deleted file mode 100644
index 257cc56..0000000
--- a/myFooFile
+++ /dev/null
@@ -1 +0,0 @@
-foo
myFooFile
myBarFile
foo
创建时
bar
它不可能两者兼而有之,所以我们会有冲突。同时它
可以
做我们做过的重命名,所以它在工作树中做过(仅此),离开
MyBar文件
包含
FOO公司
.
你想知道:
如何妥善解决我们加入的樱桃采摘冲突,最终…我的BAR文件包含BAR?
所有的Git需要的是你写,到工作树,一个版本的
MyBar文件
包含所需的内容,然后调整索引,使其条目处于阶段0。目前,索引中的内容是:
$ git ls-files --stage
100644 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 2 myBarFile
和
MyBar文件
有你的内容
git checkout branch-a -- myBarFile
在Git冲突解决过程中…
一
git show
提取
文件版本:
$ git show branch-a:myBarFile > tmp
$ cat tmp
bar
$ mv tmp myBarFile
$ git add myBarFile
$ git ls-files --stage
100644 5716ca5987cbf97d6bb54920bea6adde242d87e6 0 myBarFile
git cherry-pick --continue
git commit
要完成这个樱桃采摘:
$ git cherry-pick --continue
rm myFooFile add myBarFile
[master 1837c17] rm myFooFile add myBarFile
Date: Fri Jun 15 22:21:48 2018 -0700
1 file changed, 1 insertion(+), 1 deletion(-)
git log --oneline
显示所需内容:
1837c17 (HEAD -> master) rm myFooFile add myBarFile
a30b874 git mv myFooFile myBarFile
bde7df5 First commit add myFooFile
log.decorate = auto
在我的配置中)。