Git交互式变基 - 如何仅将此分支提交进行变基?

3
我有一个本地分支,我们称之为DEV。该分支的提交历史如下:
module_A: 添加CRC校验(9273467932)
module_B: 更改关闭过程 (84705723)
从XXX合并请求#918(265424)
module_D: 清理(3859236)
从解决排水问题的分支合并(38572693)
(...)
现在,我不喜欢第四个提交的消息“清理”,它太模糊了,所以我想编辑它。然后我这样操作:
git rebase -i 3859236

当我打开vim并将3859236标记为edit时,接下来我执行git commit --ammend并将提交消息更改为更具描述性的内容。到目前为止还不错。因为这是我想要做的唯一更改,所以最后我发出git rebase --continue

但是惊奇的事情发生了:

正在进行交互式变基: (...) 两个修改: tools/src/file.c

这怎么可能?我只是更改了提交消息,那么Git如何引发冲突文件呢?

我的理论是,Git试图从我合并的提交中重新检视所有提交,这可能会导致冲突。尤其是如果在此期间我拉取了这些分支。

我已经尝试了所有方法。例如添加-p以保留提交消息;-r用于重新创建合并提交--没有成功,它总是尝试重新定义这些分支。我还可以看到它在编辑待办列表时。它列出了不在当前分支上但在我合并或cherry pick的分支上的提交。

因此,我的问题归结为这个——如何限制变基只重新组织这个特定分支的提交。或者,如何在不重新定义的情况下编辑和压缩此分支中的提交。

2个回答

2
你不想“编辑”修订版……你想“重新措辞”它。最初的回答。
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.

你之所以会得到这样的消息,是因为你在重新定位(rebase)背后提交了更改。如果想要使用编辑(edit),当版本停止时,将更改添加到索引中,然后运行 git rebase --continue ,不要自己提交......如果选择使用 reword,一旦你保存了文件内容并退出编辑器,rebase 将自动继续,无需再次请求。


是的,这是一个选项。但是我想知道为什么在rebase期间进行提交修改会引发冲突,而这些冲突已经在合并期间解决了。这是因为在合并期间我们创建了合并提交,该提交应用于当前分支,但是当我们稍后执行rebase时,git会从已合并的分支中重新整理所有提交历史记录,这确实有所不同。 - DannyS

1
尝试相同的过程,但使用rebase -i命令,并使用要编辑的提交之前的提交。这将在现有提交(之前的提交)上重播您的编辑。

我不明白它如何有助于解决冲突问题? - DannyS
@DannyS 这会有所帮助,因为它会在其父提交的顶部重放您的重新提交,而不是在自身的顶部。试一试吧。 - VonC
“我想知道为什么在rebase期间修改提交会引发已经在合并期间解决的冲突”,这就是我的答案将要避免的。 - VonC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接