我有两个分支: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
到branch B
。这显然不是我想要的。因此,cherry-pick
将选择c
自祖先commit以来提交中涉及的那些文件的所有更改a
。那正确吗?如果我只想从挑差异b
来c
并把它应用到i
?
添加文件test.txt
并发出第一次提交init commit
。test.txt
就是现在:
first line
second line
创建一个新分支dev
但留在分支master
;
添加added in commit b
到文件中并发出commit b
。test.txt
就是现在:
first line
added in commit b
second line
添加added in commit c
到文件中并发出commit c
。test.txt
就是现在:
first line
added in commit b
added in commit c
second line
签出dev
分支并发出提交h
。test.txt
就是现在:
first line
second line
adding by commit h
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
看到?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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句