合并具有相同提交的 2 个分支
Merging 2 branches that have the same commit
我有以下场景:
master
test_1 (branch from master) with commit X updated with --amend
test_2 (branch from test_1) with original commit X and a new commit Y.
我是 git 的新手,我在创建第二个分支时犯了一个错误。该分支应该来自 master,而不是 test_1
的分支,我已经在 test_1
上完成了 commit X
。我在 test_2
(commit Y
) 上工作,同时我不得不为在 [=11= 上完成的 commit X
修改一些东西].
我应该如何以不必创建新提交或不必解决 commit X
与 [=14= 之间的冲突的方式将这些分支合并到 master 中] 和 commit X updated
来自 test_1
(很多文件已更改)?此外,commit Y
是在与 commit X
不同的文件上完成的。
编辑:起初我想从 master 创建一个新分支并复制为提交 Y 完成的文件并与该分支合并,但我想知道是否有 "cleaner" 解决方案。
cherry-pick
您对 test_1
和 test_2
分支的更改。为了获得 master
中的更改,切换到 master
分支并且
git cherry-pick <commit-hash-of-X> <commit-hash-of-Y>
只要有 amend
,哈希值就会发生变化。 test_1
中 X 的提交哈希将不同于 test_2
中的提交哈希。所以从 test_1
中选择 X,从 test_2
中选择 Y
我有以下场景:
master
test_1 (branch from master) with commit X updated with --amend
test_2 (branch from test_1) with original commit X and a new commit Y.
我是 git 的新手,我在创建第二个分支时犯了一个错误。该分支应该来自 master,而不是 test_1
的分支,我已经在 test_1
上完成了 commit X
。我在 test_2
(commit Y
) 上工作,同时我不得不为在 [=11= 上完成的 commit X
修改一些东西].
我应该如何以不必创建新提交或不必解决 commit X
与 [=14= 之间的冲突的方式将这些分支合并到 master 中] 和 commit X updated
来自 test_1
(很多文件已更改)?此外,commit Y
是在与 commit X
不同的文件上完成的。
编辑:起初我想从 master 创建一个新分支并复制为提交 Y 完成的文件并与该分支合并,但我想知道是否有 "cleaner" 解决方案。
cherry-pick
您对 test_1
和 test_2
分支的更改。为了获得 master
中的更改,切换到 master
分支并且
git cherry-pick <commit-hash-of-X> <commit-hash-of-Y>
只要有 amend
,哈希值就会发生变化。 test_1
中 X 的提交哈希将不同于 test_2
中的提交哈希。所以从 test_1
中选择 X,从 test_2