[英]Git replace inbetween commits with another branch commits
想要移动的东西:
A--B--C--D--E--F--G--H (master)
\
\
L--M--N--O--P (feature)
想要删除DEF提交并替换为LMNOP。 最终的回购应该是
A--B--C--L--M--N--O--P--G--H (master)
不幸的是,我的Git还不够强大,有什么帮助吗?
这应该做到: git rebase F master --onto feature
这告诉Git将F..master
之间的提交移动到feature
。 现在你的仓库看起来像
A--B--C--D--E--F
\
\
L--M--N--O--P (feature)
\
\
G--H (master)
然后只需git branch -d feature
来清理旧的feature
分支,Git的垃圾回收将负责D--E--F
。
有关各种更多详细信息和一些好的示例图,请阅读rebase docs 。
您的历史记录如下:
$ git log --oneline --graph --all
* 3e680f3 H
* afd87a5 G
* 2583117 F
* 6f44661 E
* 37ba1cd D
| * 7c8d70f P
| * b953a6f O
| * 7e2f28e N
| * 95fc381 M
| * 7ca7fe9 L
|/
* c30b405 C
* 70fad86 B
* 18aedd7 A
* c32e786 Initial commit
合并feature
分支
$ git me feature
Merge made by the 'recursive' strategy.
l | 0
m | 0
n | 0
o | 0
p | 0
5 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 l
create mode 100644 m
create mode 100644 n
create mode 100644 o
create mode 100644 p
以交互方式重新设置您的主数据库,对我而言c32e786
是初始提交的哈希值:
$ git rebase -i c32e786
您将看到一个文本编辑器,其中包含提交列表。 删除不需要的提交,然后根据需要重新排列其余的提交或重新排序:
$ git log --oneline
ff6a364 H
4a9d73c G
7c8d70f P
b953a6f O
7e2f28e N
95fc381 M
7ca7fe9 L
c30b405 C
70fad86 B
18aedd7 A
c32e786 Initial commit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.