git - 修改 merge 前 Git 提交的消息

标签 git git-rewrite-history

在 merge 到远程分支之前,我提交了一些测试代码。这次 merge 有很多冲突,需要很长时间才能纠正。所以我的历史看起来像这样:

7ab562c Merge from remote branch
... whole load of commits brought across from the remote branch...
f3e71c2 Temporary TESTING COMMIT

测试代码没问题,我真的只是想更改提交消息。通常我会直接使用 git rebase -i f3e71c2^(因为这些都还没有被推送),但一位同事告诉我这会搞砸 merge 。我真的不想搞砸 merge :)

我的同事是否正确?如果是这样,我能做些什么,还是我只需要忍受这段历史?

最佳答案

你可以试试 git rebase --preserve-merges --interactive , 与:

-p
--preserve-merges

Instead of ignoring merges, try to recreate them.

手册页的 BUG 部分包括:

The todo list presented by --preserve-merges --interactive does not represent the topology of the revision graph.
Editing commits and rewording their commit messages should work fine, but attempts to reorder commits tend to produce counterintuitive results.


作为jthillcomment描述(因为如果冲突解决是记录器,-p 将更好地保留 merge ):

You can retroactively light rerere for a merge:

git config rerere.enabled true
git checkout $merge^1

git merge $merge^2
# for Windows: 
# git merge $merge^^2

git read-tree --reset -u $merge
git commit -m-
git checkout @{-1}

Soufiane Roui 所述在 the comments :

For Windows CMD users, use double caret to point for parents of the merge commit (e.g $merge^^1 instead of $merge^1).
Because the caret is considered as an escape character.

关于git - 修改 merge 前 Git 提交的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16539346/

相关文章:

git : a file in the history without commits on it, 怎么解释呢?

git - 从 git repo 中完全删除一个文件(从某个时间点开始)

git - 从 git 历史记录中删除未使用的 Assets

git - 执行 "Checkout with Rebase"然后在 Intellij IDEA 中推送 merge 文件的正确方法是什么

git - 在 SourceTree 中将提交消息主题保持在 50 个字符以下

git - 如何安全地提交 .git 目录

git - 使用 shell 脚本更改 *n* 次提交的 git 历史记录(提交日期)

git - 截断 GIT 历史(有 2 个永久分支)

node.js - GIT SCM 中的 Npx 未定义路径

git - 将现有的 Git 存储库迁移到新的支持 Git LFS 的存储库