git 正在尝试在 'git rebase --interactive <commit>'

问题描述 投票:0回答:1

我在 git 中有如下历史记录:

<hash2> commit2
<hash1> commit1
<hash0> initial commit

我执行

git rebase -i <hash0>
并选择编辑 (
pick -> e
) 两个提交(
commit1
commit2
)。编辑
commit1
后,我尝试通过执行
git commit --amend
来提交更改,我编辑提交消息并保存它,
git
说“确定”。

然后我做了

git rebase --continue
,现在
git
正在尝试将
commit2
合并到
commit1
中,它说应用
commit2
后存在一些冲突,所以我编辑这个提交并保存它,但是当我做
git commit --amend
而不是像
commit2
那样编写更改,它将它们合并到
commit1

也许我错过了一些东西,为什么会发生这种情况以及如何解决这个问题(我希望我的 3 次提交历史记录在变基后保持相同)?

git git-commit git-rebase git-history
1个回答
0
投票

当您进行交互式变基并选择编辑提交时,您需要处理每个提交权限以保持历史记录相同。首先,使用

git rebase -i <hash0>
启动变基,并将 commit1 和 commit2 的
pick
更改为
edit
。当它停止在 commit1 时,进行更改,然后使用
git commit --amend
git rebase --continue
。然后它在 commit2 处停止并显示冲突。解决冲突,然后使用
git add <resolved-files>
来上演它们。不用
git commit --amend
,只需使用
git commit
单独保存commit2,然后用
git rebase --continue
继续rebase。这样,每个提交都保持独立,并且历史记录在变基后看起来是相同的。

© www.soinside.com 2019 - 2024. All rights reserved.