将提交哈希添加到每个提交消息

发布于 2025-01-09 15:14:01 字数 355 浏览 3 评论 0原文

我想知道如何在 git filter-repo --commit-callback 的帮助下向每个提交消息添加原始提交哈希

我尝试过的是 git filter-repo -- commit-callback script.py --force,其中 script.py 包含

def commit_callback(commit):
    commit.message = commit.message + '\n' + commit.original_id

但它没有效果,我也尝试通过 commit.author_name 更改作者姓名,它没有有什么影响有

什么解决办法吗?

I'm wondering how to add an original commit hash to each commit message with a help of git filter-repo --commit-callback

What I've tried is git filter-repo --commit-callback script.py --force, where script.py contains

def commit_callback(commit):
    commit.message = commit.message + '\n' + commit.original_id

But it has no effect, also I've tried to change author name via commit.author_name, it does not have any effect either

Any solutions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摇划花蜜的午后 2025-01-16 15:14:01

我认为这个答案对你来说来得太晚了,但对于遇到同样问题的其他人来说:

你的脚本定义了一个应用于每个提交的函数,但它必须包含每个提交需要执行的内容。
目前,您的脚本所做的只是定义一个从未调用的函数。如果删除 def 行(和缩进),脚本实际上将按照您的预期运行。

那么脚本仍然会失败,因为 commit 中的字段是 bytes 而不是 str。固定 python 文件的完整内容为:

commit.message = commit.message + b'\n' + commit.original_id

I assume this answer comes too late for you, but for other people who run into the same issue:

Your script defines a function to be applied for each commit, but it must contain what needs to be executed for each commit.
At the moment all your script does is defining a function that does never called. If you remove the def line (and indentation) the script will actually run like you intended.

The script will still fail then, because the fields in commit are bytes and not str. The complete content of the fixed python file would be:

commit.message = commit.message + b'\n' + commit.original_id
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文