git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Keep original author with git merge --squash?

From
Jeff King <peff@peff.net>
Date
Feb 12, 2015, 22:50 UTC
Message-ID
<20150212225003.GA20763@peff.net>
In-Reply-To
<xmqq4mqqrc70.fsf@gitster.dls.corp.google.com>
On Thu, Feb 12, 2015 at 02:34:43PM -0800, Junio C Hamano wrote:
Show 18 quoted lines
> I actually was hoping that this would extend to cases other than
> "git merge --squash".
> 
> When running "git commit" and:
> 
>  - You didn't use a more explicit method of specifying the
>    authorship identity (--author, --date, -C, -c --amend,
>    --reset-author options, or environment variables GIT_AUTHOR_*);
> 
>  - You have commit.useAuthorFromEditorComment variable;
> 
>  - You have "# Author: " line that are identical in the result of
>    the editor,
> 
> then use that author.  That would allow "git commit --amend" to
> update a misspelled author name, for example.
> 
> Is that a bit too liberal?  Would it invite mistakes?
I like this direction in general.

What happens if there is no "Author:" line in the output? Do we do the equivalent "--reset-author"? That seems slightly error-prone to me. It is not uncommon for me to delete to the end file in my editor to drop cruft (e.g., in an interactive rebase with a "squash" command, I very often drop the final commit message, and it is simpler to just delete to the end of file than to delete to the top of the comment block).

I wonder if we should have some markers in the commented-out section that indicate it even exists, like:

  # --- Lines in this section affect the commit authorship ---
  # Author: ...
  # ---

Of course that is nice when you are editing an existing Author line, but not so much when you have to remember to type that line yourself (because you are adding an author attribution when there was not one before).

So probably a saner thing is that a missing "Author:" line does nothing, and using "Author: " (with no text) does a reset.

Also, on the topic of "merge --squash". I never use it myself, but having experimented with it due to this thread, I found the template it sticks into COMMIT_EDITMSG to be horribly unfriendly for munging. For example, with two simple commits, I get:

    Squashed commit of the following:
    
    commit 6821a8ac920ed00675e4aec10dcef705211105cd
    Author: Jeff King <peff@peff.net>
    Date:   Thu Feb 12 17:39:28 2015 -0500
    
        commit subject 2
    
        commit body 2
    
    commit b0840bb4bbfe00b6ed8c7c4d483f11d126fa2d69
    Author: Jeff King <peff@peff.net>
    Date:   Thu Feb 12 17:39:28 2015 -0500
    
        commit subject 1
    
        commit body 1

I guess that is helpful if you want to keep a complete log of what got squashed, but I doubt that is the common case (if you did, then doing a real merge would probably be in order). But to munge that into a usable single commit message, I have to:

  1. Drop the header fields. We could mark these with "#" instead (which
     would also make the "# Author: " proposal here work.
  2. Reindent all of the actual message lines!
  3. Probably reorder the commit messages, since they are
     reverse-chronological here.
I would find something like:
    # commit b0840bb4bbfe00b6ed8c7c4d483f11d126fa2d69
    # Author: Jeff King <peff@peff.net>
    # Date:   Thu Feb 12 17:39:28 2015 -0500
    
    commit subject 1
    
    commit body 1
    # ... and then the second commit ...

much more friendly, and closer to what interactive rebase's squash does. It also raises a question for the proposal in this thread: if there are multiple "Author:" lines, which one do we take? The first, or the last? I think in the proposed chronological-order format I just showed, it would make sense to take the first.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 18 in “Keep original author with git merge --squash?”
  1. David GlasserFeb 11, 2015
  2. Jeff KingFeb 12, 2015
  3. Michael HaggertyFeb 12, 2015
  4. Jeff KingFeb 12, 2015
  5. David GlasserFeb 12, 2015
  6. Junio C HamanoFeb 12, 2015
  7. David GlasserFeb 12, 2015
  8. Junio C HamanoFeb 12, 2015
  9. David GlasserFeb 12, 2015
  10. David GlasserFeb 12, 2015
  11. Junio C HamanoFeb 12, 2015
  12. Jeff KingFeb 12, 2015
  13. Junio C HamanoFeb 12, 2015
  14. Jeff KingFeb 13, 2015
  15. Junio C HamanoFeb 13, 2015
  16. Jeff KingFeb 13, 2015
  17. David GlasserFeb 13, 2015
  18. David GlasserFeb 13, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.