git - 如何在当前分支中添加提交以将内容更改为另一个分支中的特定提交
问题描述
我有branchA
and 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
解决方案
另一种选择是:
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
推荐阅读
- java - 如何在应用程序的生命周期中保持绑定服务运行?
- c - 在c中读取时解析文件
- python-3.x - 如何在使用 pyaudio 时不获取 OSError: [Errno -9993] I/O 设备的非法组合
- javascript - What query do I use to return unique rows in
.find() - c++ - char数组返回main时printf printig不一致的垃圾
- tensorflow - 针对特定类对 Pascal_Voc 进行微调
- r - 将数据框导入 R 时标记 .xlsx 文件中的特定数据
- mysql - 在这种情况下在 mysql 上显示行
- c - C中的字符串文字数组如何存储?
- swift - 如何在 Apple Map IOS 中在集群注解和非集群注解之间切换