【发布时间】:2018-06-15 12:48:37
【问题描述】:
假设以下 git 历史记录
M (master) <- merge that required resolving a conflict, e.g. coming from F and G
| \
| |
F G
| |
C D <- commit to edit (D), unrelated to the merge conflict (e.g. adding a new file)
| |
| /
B
|
A <- initial commit
我想要实现的是编辑提交 D(重写历史)。我正在使用命令git rebase --interactive --preserve-merges A master,将提交D标记为要编辑,在变基停止时对其进行编辑,修改提交和git rebase --continue。
在M 提交之前我收到的是解决冲突的请求。将分支合并到M 时,同样的冲突已经解决,因此我希望变基能够顺利进行。
$ git rebase --continue
Auto-merging yet-another-test.txt
CONFLICT (content): Merge conflict in yet-another-test.txt
Automatic merge failed; fix conflicts and then commit the result.
Error redoing merge d01ffb203aae9ef450ae7a863de5fce2ed5184bb
您可以找到示例here,您可以尝试例如git rebase -i -p 8b58 master 和 edit 30c7 提交
我问的原因是因为我的真实仓库的 git 历史非常复杂,一路上有很多合并(总共大约 300 次提交),我需要编辑的提交接近初始提交,所以我想保留历史记录(避免挤压),但我宁愿不再解决所有冲突。
有没有更好的方法来做到这一点?
在 git for windows 2.17.1(最近)上尝试过。
【问题讨论】:
-
以这种方式重写会很复杂,如果不是不可能的话。为什么不直接修复分支上需要修复的任何内容,然后将其合并?净结果是一样的吗?
-
原因是我想要重写历史记录 - 隐藏最初放入提交的数据,但仍保留整个更改历史记录
-
过程非常复杂,有很多合并,我需要编辑的提交接近初始提交。当您进行重写时,您需要重新应用上游的所有更改,而不仅仅是您重写的修订。所以所有这 300 次提交都需要重做。这真的不实用。
-
我知道,如果它不起作用,我将需要另一种方法来摆脱更改历史记录。不过,这个问题归结为:为什么 git 无法重新应用包含已解决冲突的合并提交?
标签: git git-rebase git-rewrite-history