Git交互式交互基准重设-如何仅对该分支提交进行基准重设?

时间:2019-07-07 19:26:08

标签: git version-control rebase

我有一个本地分支,我们称之为DEV。分支的提交历史记录如下:

module_A:添加CRC验证(9273467932)

module_B:更改关闭程序(84705723)

合并来自XXX的提取请求#918(265424)

module_D:清理(3859236)

合并分支fix_for_drain_issue(38572693)

(...)

现在,我不喜欢模糊的第四条提交消息“ cleanup”,所以我想对其进行编辑。所以我去:

git rebase -i 3859236

vim打开,我将3859236标记为 edit 。接下来,我做git commit --ammend并将提交消息更改为更具描述性。到目前为止,一切都很好。由于这是我唯一想做的更改,因此我最终发出了git rebase --continue 惊喜在这里:

interactive rebase in progress: (...) both modified: tools/src/file.c 那怎么可能?我所做的只是更改提交消息,对吗?那么git如何引发冲突文件呢? 我的理论是git尝试从我拥有的合并提交中重新确定所有提交的基准,这可能会导致冲突。特别是在此期间,如果我已经撤消了这些分支。

我已经尝试了一切-p来保存提交消息; -r重新创建合并提交-没有成功,它总是试图重新建立这些分支的基础。当显示变基编辑任务列表时,我也会看到它。它列出的提交不在我的当前分支上,而是在我合并或从中挑选的这些分支上。

所以我的问题可以归结为这一点-如何限制重新设置基础,使其仅重组来自该特定分支的提交。或者,也可以选择如何编辑,壁球有时会在此分支中提交而无需重新设置基础。

2 个答案:

答案 0 :(得分: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背后进行提交。如果要使用编辑,则在修订停止时,将更改添加到索引中,然后运行 git rebase --continue ,就不必自己提交...如果您选择使用 reword ,将文件内容保存在编辑器中后,退出该文件时,rebase将自动继续,而无需要求它继续。

答案 1 :(得分:1)

尝试相同的过程,但是使用rebase -i,在要编辑的内容之前使用

这将在现有提交(之前的提交)之上重放您的编辑内容