Skip to content

blame doesn't preserve multi-line commit messages #485

Closed

Description

@ajaska

The Commit objects returned by blame and blame_incremental only contain the first line of the commit message (the summary).

Obviously, it is harder to return the full commit message because git blame -p only returns the summary.

Activity

  1. Byron commented on Jul 13, 2016

    @Byron
    Member

    When blaming, you will receive BlameEntry objects, which provide you with the Commit object via its .commit field. You should be able to obtain the message via blame_entry.commit.message.
    Considering the existence of a suitable workaround, I believe it's ok to close this issue right away. However, if there is anything else, please feel free to comment and possibly get the ticket re-opened (maybe there is a problem I didn't see).

  2. ajaska commented on Jul 13, 2016

    @ajaska
    Author

    Yes, I am referring to those .commit objects.

    Here, I made some easy scripts to run to reproduce this. Run the first to set up the git env (in a new directory) and then run the second to see that only the first line of the commit message is displayed.

    #!/bin/bash
    
    rm ./some-file
    rm -rf ./.git/
    
    git init
    
    echo "this is" >> some-file
    echo "some text" >> some-file
    git add some-file
    git commit -m "Initial commit"
    
    echo "some more text" >> some-file
    git add some-file
    git commit -m "Commit two summary
    
    More detailed text here
    Could be really detailed :)
    
    Blah blah blah"
    import git
    
    repo = git.Repo("./")
    
    
    def get_incremental():
        for blame_entry in repo.blame_incremental('HEAD', 'some-file'):
            if 3 in blame_entry.linenos:
                return blame_entry
    
    
    def get_non_incremental():
        for commit, lines in repo.blame('HEAD', 'some-file'):
            if 'some more text' in lines:
                return commit
    
    
    print(get_incremental().commit.message)
    
    print(get_non_incremental().message)
  3. ajaska commented on Jul 13, 2016

    @ajaska
    Author

    You can see here where Commit objects are being created with code that looks like message = summary :)

    message=safe_decode(props[b'summary']))

    message=info['summary'])

  4. reopened this on Jul 17, 2016
  5. added this to the v2.0.8 - Bugfixes milestone on Jul 17, 2016
  6. Byron commented on Jul 17, 2016

    @Byron
    Member

    Thanks for the feedback ! It's clear to me now why this indeed doesn't work as expected.
    The Commit object fooled me, and might do so with many others using this API.
    The most straightforward solution seems to simply not fill in the summary, as the commit will then lazily fetch the data when queried.

  7. added a commit that references this issue on Jan 24, 2026
    2ff3a3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions