【发布时间】:2020-04-01 16:38:08
【问题描述】:
我一直在使用cherry-pick,所以我应该对这句话很有信心:
- cherry-pick 只接受在樱桃挑选提交中所做的更改。停下来。
但碰巧在通常的合并中,它还从另一个提交中进行了不需要的更改。
我简化了我的用例:
- 我在 master 之上挑选
tocherry提交,避免tonotcherry更改
user@laptop:(master)test$ git log --graph --oneline --abbrev-commit --decorate --all
* 6fee67e (HEAD -> master) unused
| * 7c9de69 (feature) tocherry
| * fffe063 tonotcherry
|/
* 970888c init
user@laptop:(master)test$ git show fffe063
commit fffe063be9cd11c0fb8406a8e8806bfd2ea71d74
tonotcherry
diff --git a/Class.cs b/Class.cs
index 8fa6580..ae5f69e 100644
--- a/Class.cs
+++ b/Class.cs
@@ -5,12 +5,14 @@ namespace ciao
public class Test
{
private string attribute1;
+ private string attribute2;
public Test Test(
- string _attribute1
- )
+ string _attribute1,
+ string _attribute2)
{
this.attribute1 = _attribute1;
+ this.attribute2 = _attribute2;
}
}
}
user@laptop:(master)test$ git log --graph --oneline --abbrev-commit --decorate --all
* 6fee67e (HEAD -> master) unused
| * 7c9de69 (feature) tocherry
| * fffe063 tonotcherry
|/
* 970888c init
user@laptop:(master)test$ git show fffe063
commit fffe063be9cd11c0fb8406a8e8806bfd2ea71d74
tonotcherry
diff --git a/Class.cs b/Class.cs
index 8fa6580..ae5f69e 100644
--- a/Class.cs
+++ b/Class.cs
@@ -5,12 +5,14 @@ namespace ciao
public class Test
{
private string attribute1;
+ private string attribute2;
public Test Test(
- string _attribute1
- )
+ string _attribute1,
+ string _attribute2)
{
this.attribute1 = _attribute1;
+ this.attribute2 = _attribute2;
}
}
}
user@laptop:(master)test$ git show 7c9de69
commit 7c9de69d8461642867b7c5b1395b11abbf918b96 (feature)
tocherry
diff --git a/Class.cs b/Class.cs
index ae5f69e..f5f88ff 100644
--- a/Class.cs
+++ b/Class.cs
@@ -6,13 +6,19 @@ namespace ciao
{
private string attribute1;
private string attribute2;
+ private string attribute3;
+ private string attribute4;
public Test Test(
string _attribute1,
- string _attribute2)
+ string _attribute2,
+ string _attribute3,
+ string _attribute4)
{
this.attribute1 = _attribute1;
this.attribute2 = _attribute2;
+ this.attribute3 = _attribute3;
+ this.attribute4 = _attribute4;
}
}
}
user@laptop:(master)test$ git show 6fee67e
commit 6fee67e42b675de94b385bca461336326a36c46f (HEAD -> master)
unused
diff --git a/Class.cs b/Class.cs
index 8fa6580..c189487 100644
--- a/Class.cs
+++ b/Class.cs
@@ -12,5 +12,9 @@ namespace ciao
{
this.attribute1 = _attribute1;
}
+
+ public string someFunction() {
+ return "";
+ }
}
}
user@laptop:(master)test$ git cherry-pick -x 7c9de69d8461642867b7c5b1395b11abbf918b96
error: could not apply 7c9de69... tocherry
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'
user@laptop:(master)test$ cat Class.cs
using System;
namespace ciao
{
public class Test
{
private string attribute1;
<<<<<<< HEAD
public Test Test(
string _attribute1
)
{
this.attribute1 = _attribute1;
}
public string someFunction() {
return "";
=======
private string attribute2;
private string attribute3;
private string attribute4;
public Test Test(
string _attribute1,
string _attribute2,
string _attribute3,
string _attribute4)
{
this.attribute1 = _attribute1;
this.attribute2 = _attribute2;
this.attribute3 = _attribute3;
this.attribute4 = _attribute4;
>>>>>>> 7c9de69... tocherry
}
}
}
除了构造函数中的输入参数,逗号和括号不明确,我应该在cherry-pick提交期间看不到attribute2,因为那只是fffe063的一部分。
这与 git 如何存储差异和应用合并有关吗?我怎么能预测呢?有什么办法可以避免这种行为?
提前致谢
【问题讨论】:
标签: git