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

Re: git merge and cherry-pick and duplicated commits?

From
Alex Riesen <raa.lkml@gmail.com>
Date
Jan 14, 2009, 13:47 UTC
Message-ID
<81b0412b0901140547u2fbd2feh89fc80f64b9bab81@mail.gmail.com>
In-Reply-To
<200901140941.17110.trast@student.ethz.ch>
2009/1/14 Thomas Rast <trast@student.ethz.ch>:
Show 18 quoted lines
> skillzero@gmail.com wrote:
>> That's what I was somewhat disappointed by. Even though the result of
>> the commit had a different hash, I assumed git would keep some kind of
>> internal per-commit hash so it could tell later that two commits were
>> the same and not re-apply them.
>
> I think there's an important misunderstanding here: merging A into B
> does *not* have anything to do with commits, or history for that
> matter, beyond the differences from $(git merge-base A B) to A and
> B.[*]
>
> Along the same lines, nothing is ever re-applied during merging.
> git-merge just figures out that you made the same change on both
> sides, so it must have been a good change, so it must go into the end
> result.  *How* you arrived at the same change---say, by
> cherry-picking, or by getting the same result in that region from
> otherwise different commits, or even from several commits---does *not*
> matter in any way.

Yes, merge only considers what bytes (aka contents of trees-directories and blobs-files) do the branches to be merged have, compares them (by comparing their hashes) and if there are differences tries to mix them together according to the merge rules described somewhere in Documentation.

So this all is really just about what the branches contain, not how they got it. It is the conflict resolution algorithm which uses the history to find the best possible source blob or tree which was changed by conflicting branches so the "mix" can be prepared as close as possible to what would we do if we went looking for the pieces manually.

Previous: Thomas RastNext: skillzero@gmail.com
Message 14 of 16 in “git merge and cherry-pick and duplicated commits?”
  1. skillzero@gmail.comJan 14, 2009
  2. Brian GernhardtJan 14, 2009
  3. skillzero@gmail.comJan 14, 2009
  4. Johannes SixtJan 14, 2009
  5. skillzero@gmail.comJan 14, 2009
  6. Johannes SixtJan 14, 2009
  7. skillzero@gmail.comJan 14, 2009
  8. Peter BaumannJan 14, 2009
  9. Junio C HamanoJan 14, 2009
  10. Markus HeidelbergJan 15, 2009
  11. Boaz HarroshJan 14, 2009
  12. Nanako ShiraishiJan 14, 2009
  13. Thomas RastJan 14, 2009
  14. Alex RiesenJan 14, 2009
  15. skillzero@gmail.comJan 14, 2009
  16. Sitaram ChamartyJan 14, 2009

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.