ka3ak
ka3ak

Reputation: 3181

Change old commit messages in Git

I have to replace a text with another one in all the git repo commit messages. It seems to be possible with git rebase -i ... that opens a text editor but I have to do it automatically. Is it doable with some of the git commands or maybe with a Java library?

Upvotes: 3

Views: 445

Answers (2)

Stefan Varga
Stefan Varga

Reputation: 508

git filter-branch is not recommended.

Use an alternative history filtering tool such as git filter-repo.

git filter-repo --message-callback 'return re.sub(b"#", b"GH-", message)' --force --replace-refs delete-no-add

Upvotes: 0

OhleC
OhleC

Reputation: 2890

git filter-branch is the tool to use for automatic bulk history rewriting.

Specifically --msg-filter:

--msg-filter This is the filter for rewriting the commit messages. The argument is evaluated in the shell with the original commit message on standard input; its standard output is used as the new commit message.

In your case, a simple sed as the command might suffice.

Upvotes: 4

Related Questions