How to change git commit message without changing commit hash

前端 未结 3 891
失恋的感觉
失恋的感觉 2021-01-03 21:16

The title is not exact, but I can\'t express it better in a single line.

  • I actually know how to change git commit message like here.
  • But I know it alwa
3条回答
  •  情话喂你
    2021-01-03 22:07

    As various people have pointed out (e.g. in VonC's very useful answer), git notes really is the mechanism you're looking for. Is it not enough for you to change your alias to the following?

    git log --oneline --show-notes
    

    Presumably it's only occasionally that you'll have to add a note to a commit, and the notes will visually stand out in the output of that command.

    If you really want to replace the subject of each commit if notes exist, you could always create a script along the lines of:

    for c in $(git rev-list HEAD)
    do
        n=$(git notes show $c 2> /dev/null)
        m=$(git show --oneline $c|head -1)
        if [ -n "$n" ]
        then
           m=${m/ */ $n}
        fi
        echo $m
    done
    

    ... but that's a lot uglier for little gain, in my opinion.

提交回复
热议问题