git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: E R <pc88mxer@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: finding the merge of two or more commits
Date: Fri, 30 Oct 2009 16:38:12 -0700 (PDT)	[thread overview]
Message-ID: <m3iqdwcv17.fsf@localhost.localdomain> (raw)
In-Reply-To: <3a69fa7c0910291412l439f7f61vd3b55a77cd7e10b5@mail.gmail.com>

E R <pc88mxer@gmail.com> writes:

> Given two commits c1 and c2, is it possible to ask git if there are
> any commits in the repository that were created by either a sequence
> of commands like:
> 
> git checkout c1
> git merge c2
> 
> or:
> 
> git checkout c2
> git merge c1
> 
> with any required conflict resolution?
> 
> That is, I don't want to merge c1 and c2 myself, but I want to know if
> someone else has merged c1 and c2, performed any conflict resolution
> and committed the result.

I assume that commits c1 and c2 are not one ancestor of the other (are
not in fast-forward relation).

Translating your question into question about DAG of revisions, you
want to check if there is branch for which both c1 and c2 are
reachable from:

  c1sha=$(git rev-parse c1)
  c2sha=$(git rev-parse c2)
  git for-each-ref --format="%(refname)" refs/heads/ |
  while read refname
  do 
      b1=$(git merge-base c1 $refname)
      b2=$(git merge-base c2 $refname)
      if [ "$b1" = "$c1sha" -a "$b2" = "$c2sha" ]
      then
          print ${refname#refs/heads/}
      fi
  done

Instead of comparing git-merge-base with SHA-1 of c1 and c2
respoectively, you can count commits:

  git for-each-ref --format="%(refname)" refs/heads/ |
  while read refname
  do 
      count1=$(git rev-list c1..$refname | wc -l)
      count2=$(git rev-list c2..$refname | wc -l)
      if [ "$count1" > 0  -a  "$count2" > 0 ]
      then
          print ${refname#refs/heads/}
      fi
  done

Not tested!

-- 
Jakub Narebski
Poland
ShadeHawk on #git

      parent reply	other threads:[~2009-10-30 23:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-29 21:12 finding the merge of two or more commits E R
2009-10-29 21:34 ` Avery Pennarun
2009-10-30 18:04   ` Jeff King
2009-10-30 23:38 ` Jakub Narebski [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=m3iqdwcv17.fsf@localhost.localdomain \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pc88mxer@gmail.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).