Skip to content

Amending a signed commit overwrites author #2784

Open

Description

@ItsHarper

Describe the bug

Amending a signed commit overwrites the author (bad) and the committer (good).

Amending an unsigned commit does not overwrite the author (good), but it also does not overwrite the committer (bad).

To Reproduce

  1. Check out a branch where the latest commit was authored and committed by someone else
  2. Run git log --pretty=full -n 1 and verify that the Author field shows someone other than you
  3. Stage changes
  4. Open the commit dialog
  5. Press Ctrl-A to make the pending commit be an amend operation
  6. Press Ctrl-D to finish the commit
  7. Run git log --pretty=full -n 1 again
  8. Observe that either the author or committer is wrong (depending on whether the commit you amended was signed)

Expected behavior

Amending a commit should overwrite the committer, but not the author.

Context

  • OS: Chimera Linux (updated as of 2025-11-20)
  • GitUI Version: 0.27.0
  • Rust version: 1.91.0

Activity

  1. cruessler commented on Nov 22, 2025

    @cruessler
    Collaborator

    I’ll have a look!

  2. cruessler commented on Nov 27, 2025

    @cruessler
    Collaborator

    Currently, this seems to be somewhat intentional as the code for amending a commit passes None for committer which results in the committer being unchanged. I suggest we change that and override the committer with the current user, that is whatever is returned by signature_allow_undefined_name (which usually is git config --get user.name/email). I’ll prepare a PR soon!

    let new_id = commit.amend(
    Some("HEAD"),
    None,
    None,
    None,
    Some(msg),
    Some(&tree),
    )?;

  3. extrawurst commented on Nov 27, 2025

    @extrawurst
    Collaborator

    seems to be somewhat intentional [..] results in the committer being unchanged

    isnt that exactly the opposite of what the bug report states?

  4. cruessler commented on Nov 27, 2025

    @cruessler
    Collaborator

    seems to be somewhat intentional [..] results in the committer being unchanged

    isnt that exactly the opposite of what the bug report states?

    You’re absolutely right! Then I can’t seem to reproduce as the author is not overwritten if I do an amend using gitui. (This observation made me think we should probably change the committer if we amend, but now I’m not so sure anymore.) I can also try and check on a different machine to see whether I’m missing anything.

  5. ItsHarper commented on Nov 27, 2025

    @ItsHarper
    Author

    This observation made me think we should probably change the committer if we amend, but now I’m not so sure anymore.

    My understanding is that the committer should change, yeah

    Let me double-check I can reproduce myself.

  6. extrawurst commented on Nov 27, 2025

    @extrawurst
    Collaborator

    @ItsHarper

    My understanding is that the committer should change, yeah

    But your bug report says:

    Observe that you are now listed as the commit author

    So what is it ? 🙈

  7. ItsHarper commented on Nov 27, 2025

    @ItsHarper
    Author

    @ItsHarper

    My understanding is that the committer should change, yeah

    But your bug report says:

    Observe that you are now listed as the commit author

    So what is it ? 🙈

    "Committer" and "Author" are two different things. The "Author" is supposed to be the original author of the commit. The "Committer" is the last person who modified the commit in some way (amend, rebase, etc).

  8. ItsHarper commented on Nov 27, 2025

    @ItsHarper
    Author

    Screenshot demonstrating the correct behavior

    The committer changes, but the author does not

    Image

    (I meant to have that first line be git config set user.name me for clarity; setting log.showSignature is irrelevant)

    Screenshot demonstrating the incorrect behavior

    These commands were performed immediately after the previous screenshot was taken. When I ran gitui, I amended the commit and did nothing else. The author has erroneously been changed.

    Image
  9. ItsHarper commented on Nov 27, 2025

    @ItsHarper
    Author

    In case you're looking at email notifications, I've edited my last comment to have screenshots that demonstrate both the correct git behavior and the incorrect gitui behavior (it does reproduce for me).

  10. ItsHarper commented on Nov 27, 2025

    @ItsHarper
    Author

    the code for amending a commit passes None for committer which results in the committer being unchanged.

    When in doubt, read the docs:

    This creates a new commit that is exactly the same as the old commit, except that any non-None values will be updated. (emphasis mine)

    You have to explicitly provide the original author to amend().

  11. ItsHarper commented on Nov 27, 2025

    @ItsHarper
    Author

    Wait, I think the docs agree with you. Quite frankly, I'm not sure how I was reading it previously...

    Is this a bug in my distribution's version of libgit2? Chimera Linux packages 1.9.1, the latest stable release.

  12. changed the title [-]Amending a commit overwrites the author[/-] [+]Amending a commit does not handle the author and committer fields correctly[/+] on Nov 27, 2025
  13. ItsHarper commented on Nov 27, 2025

    @ItsHarper
    Author

    OK, I figured out why you couldn't reproduce it. The behavior is different depending on whether you're amending a signed commit.

    When amending a signed commit, both author and committer are overwritten.

    When amending an unsigned commit, neither author nor committer are overwritten.

    Both behaviors are wrong, just in opposite directions. I've edited the issue description.

  14. extrawurst commented on Nov 27, 2025

    @extrawurst
    Collaborator

    Oh interesting. Makes sense. the signed amend is a hack because there is no such thing in libgit2. so we undo the last commit and commit again but then it overwrite both author and committer. So we need to preserve the original author explicitly here. The other issue is the committer not being set in the actual amend call.

    @cruessler @Byron gix support for signed amend ? :)

  15. Byron commented on Nov 28, 2025

    @Byron

    Actually it does, kind-a :D. The code is currently (and originated) in GitButler. It's a very faithful and by now proven implementation, but I didn't get around to porting it over yet.

    If that was the case, signing commits in general is easy, and the same is true for amends.

  16. cruessler commented on Nov 28, 2025

    @cruessler
    Collaborator

    There’s also this addition to gitoxide GitoxideLabs/gitoxide@aacc326 that does a subset of what GitButler does. I’m interested in adding more comprehensive signing support to gitoxide, but I don’t know whether it’s on anyone else’s TODO list already. :-)

  17. Byron commented on Nov 28, 2025

    @Byron

    It's on my TODO list, but that's the case for everything gitoxide, your help would be greatly appreciated 🙏.

  18. changed the title [-]Amending a commit does not handle the author and committer fields correctly[/-] [+]Amending a signed commit overwrites author[/+] on Nov 29, 2025
  19. cruessler commented on Dec 2, 2025

    @cruessler
    Collaborator

    I just had a brief look at the code and think it should not be too difficult to address the second part of this issue. I’ll try to create a PR over the course of the next couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions