gitgit-rebasegit-config

Git istructionFormat with padding at the start not working with git rebase interactive


I want to pad spaces on the left of the user name,

[rebase]
    instructionFormat = %>(10)%al %as %s

However, the above line does not work, it has no padding effect, but if I add any char on the left of %, then it works. Also, %<(10) works in .gitconfig. And the same format works from command line.

git log -n 10 --pretty=format:"%>(10)%al %as %s"

Solution

  • git rebase is the culprit — it trims leading (and perhaps trailing) spaces in commit messages.

    I created a test repository and added a lot of spaces in commit messages:

    $ git log -5 --oneline 
    94c44b6 Build(GHActions): Use `checkout@v4` instead of outdate>
    8430ecc       Docs: Year 2024
    0b6a56b Tests,CI: Python 3.12
    990d1b5    Docs(ANNOUNCE): Fix backticks
    c7205de CI(pip): Ensure `pip` only if needed
    

    But when I ran git rebase -i @~5 it presents me trimmed messages:

    pick c7205de CI(pip): Ensure `pip` only if needed
    pick 990d1b5 Docs(ANNOUNCE): Fix backticks
    pick 0b6a56b Tests,CI: Python 3.12
    pick 8430ecc Docs: Year 2024
    pick 94c44b6 Build(GHActions): Use `checkout@v4` instead of outdated `v2`
    

    So it seems git rebase trims messages after applying format. This means you cannot left-pad commit messages in rebase todo files. instructionFormat = |%>(10)%al %as %s works but instructionFormat = %>(10)%al %as %s doesn't.