From: Jeff King <peff@peff.net>
To: Senthil Natarajan <snatarajan@stoke.com>
Cc: git@vger.kernel.org
Subject: Re: git merge heuristic
Date: Fri, 22 Mar 2013 18:33:30 -0400 [thread overview]
Message-ID: <20130322223330.GB13207@sigill.intra.peff.net> (raw)
In-Reply-To: <ECEA5ACFB4B2BC4A81A93F032519ABCAD47F79@minsk.us.stoke.com>
On Fri, Mar 22, 2013 at 11:53:04AM -0700, Senthil Natarajan wrote:
> I want to learn about how Git compares patches while doing a merge.
> For example, if a patch has been cherry-picked from branch A to branch
> B, and then downstream we do a "git merge" from A to B, how does Git
> know to skip the cherry-picked patch?
It doesn't. Git's 3-way merge only looks at three things: where each
side of the merge ended, and what their common ancestor looked like.
So when you cherry-pick a commit, as long as the content in the file
ended up the same, there is no conflict. And it doesn't matter if it
happened by cherry-picking, or if you just happened to make a sequence
of commits that ended in the same state.
However, we do perform such detection during a rebase, in which we try
to skip patches that have already been applied upstream.
> It would have a different SHA-1, so what is the comparison
> algorithm/heuristic? What happens if the comment is different, but the
> actual patch is identical?
Yes, the commit will have a different sha1. For that, we use the
"patch-id", which is basically a sha of the contents of the diff of the
commit against its parent. See the manual for git-patch-id, git-cherry,
and the --cherry-* options of "git log".
It will not find all duplicate commits (e.g., it will miss ones where
there was a conflict during cherry-pick, or even where the context is
slightly different). However, in many cases, rebase can also realize
while applying a patch that it has already been applied, and skip it
then.
-Peff
prev parent reply other threads:[~2013-03-22 22:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-22 18:53 git merge heuristic Senthil Natarajan
2013-03-22 22:33 ` Jeff King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130322223330.GB13207@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=snatarajan@stoke.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).