我有两个分支:A和B.
A的承诺历史:a <- b <- c;B的承诺历史:a <- h <- i;假设这里只有一个文件.
b,我添加了一些像"foo"这样的文本.c,我添加了一些像"bar"这样的文本.git cherry-pick c在B分支上.我以为cherry-pick只会选择c分支的变化B.但是,它会添加foo和bar分支B.这显然不是我想要的.因此,cherry-pick将从c祖先提交后选择提交中触及的那些文件的所有更改a.是对的吗?如果我只想要什么,从挑DIFF b到c并应用到i?
添加文件test.txt并发出第一个提交init commit.test.txt就是现在:
first line
second line
Run Code Online (Sandbox Code Playgroud)创建一个新分支dev但留在分支机构master;
添加added in commit b到文件并发出提交b.test.txt就是现在:
first line
added in commit b
second line
Run Code Online (Sandbox Code Playgroud)添加added in commit c到文件并发出提交c.test.txt就是现在:
first line
added in commit b
added in commit c
second line
Run Code Online (Sandbox Code Playgroud)签出dev分支并发出提交h.test.txt就是现在:
first line
second line
adding by commit h
Run Code Online (Sandbox Code Playgroud)git cherry-pick <commit c SHA1 ID>樱桃挑选承诺c提交h.
冲突消息:
index 6a8dc57,594c6ec..0000000
@@@ -1,4 -1,4 +1,9 @@@
first line
++<<<<<<< HEAD
++=======
+ added in commit b
+ added in commit c
++>>>>>>> 06ce9b1... commit c adding another line
second line
+
+adding by commit h
Run Code Online (Sandbox Code Playgroud)看到?cherry-pick也会带来改变的提交b.
谢谢!
git cherry-pick尝试只提交一次提交。但这是通过应用需要一些上下文的补丁来实现的。提交C中所做的更改与提交b中所做的更改非常接近,因此您会遇到冲突-它不能仅仅找到必须应用更改的正确位置。并且当您有冲突时,您还会得到一些冲突的上下文,这至少是提交B的一部分。
这是没有冲突的工作方式:
$ git init
$ cat > f
line1
line2
line3
$ git add f
$ git commit -a -m "initial"
# Edited to add a line in the beginning of f
$ cat f
Commit b
line1
line2
line3
$ git commit f -m "B"
# Edited to add a line in the end of f
$ cat f
Commit b
line1
line2
line3
Commit c
$ git commit f -m "C"
$ git checkout HEAD^^
$ git cherry-pick master
$ cat f
line1
line2
line3
Commit c
Run Code Online (Sandbox Code Playgroud)