git rebase --preserve-merges 合并冲突

git rebase --preserve-merges with merge conflicts

我目前正在从 git 存储库中清除密码和其他敏感数据。我仍然希望尽可能多地保留历史,包括合并。所以我在做git rebase --perserve-merges -i <commit>。然后我编辑说明以编辑我关心的特定提交。在变基期间,我很惊讶地看到与我的密码编辑无关的合并冲突。我相信这些是历史上一些现有合并发生的冲突,并在合并时得到解决。为什么 git 不能只重播解决这些冲突的提交?

--preserve-merges--interactive 不兼容。

(本回答所有引文均来自git help rebase。)

This uses the --interactive machinery internally, but combining it with the --interactive option explicitly is generally not a good idea unless you know what you are doing (see BUGS below).

In addition, the following pairs of options are incompatible:

  • --preserve-merges and --interactive

改用--rebase-merges

--rebase-mergesintroduced in Git 2.18 and --preserve-merges was officially deprecated in Git 2.22

The --rebase-merges mode is similar in spirit to the deprecated --preserve-merges but works with interactive rebases, where commits can be reordered, inserted and dropped at will.

它仍然可能无法解决您的问题:

Any resolved merge conflicts or manual amendments in these merge commits will have to be resolved/re-applied manually.

即使它不能解决您的问题,我认为它也明确地回答了您的问题。另外,无论如何您都应该使用此选项,因为 --preserve-merges 现已弃用。

--rebase-merges 上有更多 git help rebase 条评论。我建议阅读它们。