What's the fastest way to edit hundreds of Git commit messages?

后端 未结 6 2137
梦谈多话
梦谈多话 2020-12-23 14:23

I have a fairly large Git repository with 1000s of commits, originally imported from SVN. Before I make my repo public, I\'d like to clean up a few hundred commit messages t

6条回答
  •  既然无缘
    2020-12-23 14:56

    git-filter-repo https://github.com/newren/git-filter-repo is now recommend. I used it like:

    PS C:\repository> git filter-repo --commit-callback '
    >> msg = commit.message.decode(\"utf-8\")
    >> newmsg = msg.replace(\"old string\", \"new string\")
    >> commit.message = newmsg.encode(\"utf-8\")
    >> ' --force
    New history written in 328.30 seconds; now repacking/cleaning...
    Repacking your repo and cleaning out old unneeded objects
    HEAD is now at 087f91945a blah blah
    Enumerating objects: 346091, done.
    Counting objects: 100% (346091/346091), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (82068/82068), done.
    Writing objects: 100% (346091/346091), done.
    Total 346091 (delta 259364), reused 346030 (delta 259303), pack-reused 0
    Completely finished after 443.37 seconds.
    PS C:\repository>
    

    you probably don't want to copy the powershell extra things, so here is just the command:

    git filter-repo --commit-callback '
    msg = commit.message.decode(\"utf-8\")
    newmsg = msg.replace(\"old string\", \"new string\")
    commit.message = newmsg.encode(\"utf-8\")
    ' --force
    

    If you want to hit all the branches don't use --refs HEAD. If you don't want to use --force you can run it on a clean git clone --no-checkout. This got me started: https://blog.kawzeg.com/2019/12/19/git-filter-repo.html

提交回复
热议问题