Git 自动重写分支上的 git 提交消息

2023-12-24

有什么方法可以在分支上运行脚本来重写提交消息中包含特定子字符串的所有提交消息。说我有一个像这样的回购协议 https://github.com/Norfeldt/git-history-example:

然后我想重写所有提交消息(在mybranch并不是main)开始于???? build version并附加后缀 ⚠️ (rebased since).

我可以通过 git 命令、bash 脚本或事件打字稿脚本(由 ts-node 或 deno 触发)来完成吗?


您可以使用git filter-repo https://github.com/newren/git-filter-repo as in 这个答案 https://stackoverflow.com/a/62458610/6309为了修改提交消息。

See "更新提交/标签消息 https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#_updating_commit_tag_messages“一个简单的解决方案

如果您想修改提交或标记消息,您可以使用与 --replace-text 相同的语法来执行此操作,如上所述。例如,名为表达式.txt 的文件包含

???? build version==>???? build version ⚠️ (rebased since)

然后运行

git filter-repo --replace-message expressions.txt

但这不会附加⚠️ (rebased since)不过,在提交消息的末尾。

如果你最后需要它,那么你需要一个commit-callback https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#CALLBACKS,如在回答我之前提到的 https://stackoverflow.com/a/62458610/6309.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Git 自动重写分支上的 git 提交消息 的相关文章

随机推荐