我有branchA
和branchB
,它们都是从master
分支中检出的。
branchA
具有提交commitA1
和commitA2
,而branchB
具有提交commitB1
和commitB2
。两个分支上的更改都有重叠。
我想在commitA3
中添加提交branchA
,以使branchA
中的commitB1
和branchB
看起来完全一样,而不会解决任何冲突。如何创建commitA3
?
master------------------------------------|
|---- branchA |---- branchB
|---- commitA1 s~~~~~> |---- commitB1
|---- commitA2 (current) s |---- commitB2 (current)
|---- commitA3 ~~~~~~~~~~~~~s
答案 0 :(得分:1)
另一个选择是:
git checkout branchA
git rm -r .
git checkout commitB1 -- .
git commit -am commitA3
这里:
$ git diff master..branchA
diff --git a/y b/y
new file mode 100644
index 0000000..975fbec
--- /dev/null
+++ b/y
@@ -0,0 +1 @@
+y
diff --git a/z b/z
new file mode 100644
index 0000000..b680253
--- /dev/null
+++ b/z
@@ -0,0 +1 @@
+z
$ git diff master..branchB
diff --git a/w b/w
new file mode 100644
index 0000000..e556b83
--- /dev/null
+++ b/w
@@ -0,0 +1 @@
+w
diff --git a/z b/z
new file mode 100644
index 0000000..67d0c15
--- /dev/null
+++ b/z
@@ -0,0 +1 @@
+z2
$ git diff branchA branchB
diff --git a/w b/w
new file mode 100644
index 0000000..e556b83
--- /dev/null
+++ b/w
@@ -0,0 +1 @@
+w
diff --git a/y b/y
deleted file mode 100644
index 975fbec..0000000
--- a/y
+++ /dev/null
@@ -1 +0,0 @@
-y
diff --git a/z b/z
index b680253..67d0c15 100644
--- a/z
+++ b/z
@@ -1 +1 @@
-z
+z2
$ git show-branch master branchA branchB commitB1
* [master] master
! [branchA] commitA2
! [branchB] commitB2
! [commitB1] commitB1
----
+ [branchB] commitB2
++ [commitB1] commitB1
+ [branchA] commitA2
+ [branchA^] commitA1
*+++ [master] master
$ git checkout branchA
Switched to branch 'branchA'
$ git rm -r .
rm 'x'
rm 'y'
rm 'z'
$ git checkout commitB1 -- .
$ git commit -am commitA3
[branchA 3b1b4d1] commitA3
2 files changed, 1 insertion(+), 2 deletions(-)
delete mode 100644 y
$ git diff branchA commitB1 && echo same
same
$ git show-branch master branchA branchB commitB1
! [master] master
* [branchA] commitA3
! [branchB] commitB2
! [commitB1] commitB1
----
* [branchA] commitA3
* [branchA^] commitA2
* [branchA~2] commitA1
+ [branchB] commitB2
++ [commitB1] commitB1
+*++ [master] master
答案 1 :(得分:0)
在本地仓库中,我可以执行:
rowid
在GH动作中,我实现了(通过克隆另一个存储库):
git diff origin/branchA commitB1> /tmp/commit_branch_diff.patch
git checkout branchA
git apply /tmp/commit_branch_diff.patch
git add -all .
git commit -m "commitB1"
git push origin branchA