threads / discuss / 42744

git tag --contains for cherry-picks

Subject: git tag --contains for cherry-picks

## tl;dr

3 messages between Jun 29, 2016 and Jun 30, 2016.

replies: 2people: 3as markdown or json

Laszlo Papp· Jun 29, 2016, 11:48 UTC · lore
Dear List,

We have several release branches as well as a master branch where the active development happens.

Old releases are maintained with important bug fixes or even new features in our case. It sometimes means that we need to cherry-pick commits across branches, like from master to a specific release branch.

Cherry-picking changes the hash of the commit, therefore, this may no longer work for cherry-picks:

git tag --contains
I am thinking of having something like:
git tag --contains-follow

which would follow cherry-picks. I am not sure how easily and/or efficiently this can be implemented, but my gut feeling is that in the vast majority of the cases, the content check would bail out already at the "subject line".

Again, just to recap: I would like to be able to list of releases (i.e. tags) in which a commit occurs even if it is cherry-picked because what matters for us in the end of the day is whether the feature or bugfix goes into a release.

Best Regards, Laszlo Papp

Jeff King· Jun 30, 2016, 06:22 UTC · re: Laszlo Papp · lore

Re: git tag --contains for cherry-picks

On Wed, Jun 29, 2016 at 12:48:33PM +0100, Laszlo Papp wrote:
Show 17 quoted lines
> Old releases are maintained with important bug fixes or even new features
> in our case. It sometimes means that we need to cherry-pick commits across
> branches, like from master to a specific release branch.
> 
> Cherry-picking changes the hash of the commit, therefore, this may no
> longer work for cherry-picks:
> 
> git tag --contains
> 
> I am thinking of having something like:
> 
> git tag --contains-follow
> 
> which would follow cherry-picks. I am not sure how easily and/or
> efficiently this can be implemented, but my gut feeling is that in the vast
> majority of the cases, the content check would bail out already at the
> "subject line".

Git generally considers commits "equivalent" based on the patch-id, whic his a sha1 of the diff (modulo some canonicalization).

So you could ask right now for the patch-id of a particular commit:
  git show $commit | git patch-id >needle
and then the patch-id of all tagged commits:
  git log -p --tags | git patch-id | sort >haystack

Each line will have the patch-id followed by the commit id. You can then correlate them (join is part of GNU coreutils):

  join needle haystack | cut -d' ' -f2- >synonyms

That gives you a list of synonym commits, which you can use to ask git which tags contain any of them:

  git tag $(for i in $(cat synonyms); do echo "--contains $i"; done)

The big downside is that generating the haystack is expensive (it has to do a diff on every commit). But if this is something you do a lot, you can save the haystack and incrementally update it with new commits.

Of course there are other ways of determining commit equivalence. You could find ones with duplicate commit messages, or duplicate subjects, or whatever. But if you have a cherry-picking workflow, I suspect the easiest thing may be to simply use "git cherry-pick -x", which will write the sha1 of the original commit into the cherry-picked commit message. You can then use that to correlate directly.

So there's no specific "--contains-follow" as you want, but the tools are there to do it (and more flexibly and efficiently, depending on your needs). That doesn't necessarily mean it's not a good idea to make the simple case easier, though.

-Peff
Jakub Narębski· Jun 30, 2016, 10:41 UTC · re: Jeff King · lore

Re: git tag --contains for cherry-picks

W dniu 2016-06-30 o 08:22, Jeff King pisze:
Show 22 quoted lines
> On Wed, Jun 29, 2016 at 12:48:33PM +0100, Laszlo Papp wrote:
> 
>> Old releases are maintained with important bug fixes or even new features
>> in our case. It sometimes means that we need to cherry-pick commits across
>> branches, like from master to a specific release branch.
>>
>> Cherry-picking changes the hash of the commit, therefore, this may no
>> longer work for cherry-picks:
>>
>> git tag --contains
>>
>> I am thinking of having something like:
>>
>> git tag --contains-follow
>>
>> which would follow cherry-picks. I am not sure how easily and/or
>> efficiently this can be implemented, but my gut feeling is that in the vast
>> majority of the cases, the content check would bail out already at the
>> "subject line".
> 
> Git generally considers commits "equivalent" based on the patch-id, whic
> his a sha1 of the diff (modulo some canonicalization).

The problem with patch based equivalence is that for cherry-picking on old release branches you might need to modify a patch for it to apply - and then patch-id might not detect it.

[...]
Show 6 quoted lines
> Of course there are other ways of determining commit equivalence. You
> could find ones with duplicate commit messages, or duplicate subjects,
> or whatever. But if you have a cherry-picking workflow, I suspect the
> easiest thing may be to simply use "git cherry-pick -x", which will
> write the sha1 of the original commit into the cherry-picked commit
> message. You can then use that to correlate directly.

"git log --grep=<sha-1>" would help there (or even match the specific message that "git cherry-pick -x" adds).

-- 
Jakub Narębski

← back to recent threads