'Add commit hash to each commit message

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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim