Skip to contentSkip to conversation

cherry picking changesets instead of commits

PATCH In review Geoffrey Irving 4 participants 13 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

I have a project stored in a git repository with other versions stored in both cvs and perforce (sadly). I want the ability to propagate changes back and forth between all three repositories without mangling the git history. I specifically want to avoid (1) having two copies of each commit (e.g., an initial version and a version pulled from cvsimport) and (2) commits full of git-p4 metadata (the [git-p4] lines in commit messages).

One way to do this would be to have cvs branch imported using "git cvsimport", and a perforce branch imported via "git-p4", and communicate between the cvs/p4 branches and the main git branches entirely through cherry picking. Unfortunately, "git cherry" doesn't recognize when commits with potentially different author names or log messages polluted with "[git-p4]" produce the same changeset, so if I export a change from the git master branch through cvsexportcommit and update the cvs branch with cvsimport, "git cherry" will report that the change doesn't exist on the git master branch.

Has anyone tackled this problem before? Would it be straightforward to add an option to "git cherry" to ignore differences in metadata? The cherry documentation doesn't give its criteria for when commits match, and I'm not familiar enough with the code yet to figure out those criteria directly from cmd_cherry in builtin-log.c.

Thanks,
Geoffrey

#1 lore raw
Quoted 5 lines · Geoffrey Irving

Would it be straightforward
to add an option to "git cherry" to ignore differences in metadata? The cherry documentation doesn't give its criteria for when commits match, and I'm not familiar enough with the code yet to figure out those criteria directly from cmd_cherry in builtin-log.c.

cherry does not look at metadata at all. It compares patch-ids.

#2 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Geoffrey Irving

Would it be straightforward
to add an option to "git cherry" to ignore differences in metadata? The cherry documentation doesn't give its criteria for when commits match, and I'm not familiar enough with the code yet to figure out those criteria directly from cmd_cherry in builtin-log.c.

cherry does not look at metadata at all. It compares patch-ids.

Can you define what a patch-id is?

Geoffrey

#3 lore raw
Quoted 10 lines · Geoffrey Irving
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Geoffrey Irving

Would it be straightforward
to add an option to "git cherry" to ignore differences in metadata? The cherry documentation doesn't give its criteria for when commits match, and I'm not familiar enough with the code yet to figure out those criteria directly from cmd_cherry in builtin-log.c.

Quoted 3 lines
Quoted 1 line

cherry does not look at metadata at all. It compares patch-ids.

Can you define what a patch-id is?

$ man git-patch-id
#4 lore raw
Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Geoffrey Irving
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Geoffrey Irving

Would it be straightforward
to add an option to "git cherry" to ignore differences in metadata? The cherry documentation doesn't give its criteria for when commits match, and I'm not familiar enough with the code yet to figure out those criteria directly from cmd_cherry in builtin-log.c.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

cherry does not look at metadata at all. It compares patch-ids.

Can you define what a patch-id is?

$ man git-patch-id

Thanks! Here's a patch to avoid duplicating this particular ignorant question.

Geoffrey

commit a1bac5e1aa52f9a78733aa35a0a7e820df618301

Author: Geoffrey Irving <[email protected]>
Date:   Wed May 28 12:38:11 2008 -0700

doc: mention git-patch-id in git-cherry documentation

Documentation/git-cherry.txt +0 -0
index b0468aa..9817fb5 100644
@@ -41,6 +41,8 @@ has been applied <upstream> under a different commit

id. For example,
this will happen if you're feeding patches <upstream> via email rather than pushing or pulling commits directly.

+For details about how patches are compared, see git-patch-id. +

OPTIONS
-------

#5 lore raw
Quoted 11 lines · Geoffrey Irving

commit a1bac5e1aa52f9a78733aa35a0a7e820df618301

Author: Geoffrey Irving <[email protected]>
Date:   Wed May 28 12:38:11 2008 -0700

doc: mention git-patch-id in git-cherry documentation

Documentation/git-cherry.txt +0 -0
index b0468aa..9817fb5 100644

Documentation/git-cherry.txt has been applied <upstream> under a different commit · line 46

Quoted 6 lines
Documentation/git-cherry.txt +2 -0
@@ -41,6 +41,8 @@ has been applied <upstream> under a different commit
 id.  For example,
 this will happen if you're feeding patches <upstream> via email rather
 than pushing or pulling commits directly.
 
+For details about how patches are compared, see git-patch-id.
+

Thanks.

In manual pages, "SEE ALSO" section is a more appropriate place to do this kind of thing.

#6 lore raw
Quoted 17 lines · Junio C Hamano
Quoted 15 lines · Geoffrey Irving

commit a1bac5e1aa52f9a78733aa35a0a7e820df618301

Author: Geoffrey Irving <[email protected]>
Date:   Wed May 28 12:38:11 2008 -0700

doc: mention git-patch-id in git-cherry documentation

Documentation/git-cherry.txt +0 -0
index b0468aa..9817fb5 100644
@@ -41,6 +41,8 @@ has been applied <upstream> under a different commit
 id.  For example,
 this will happen if you're feeding patches <upstream> via email rather
 than pushing or pulling commits directly.
 
Quoted 7 lines

Documentation/git-cherry.txt has been applied <upstream> under a different commit · line 46

Quoted 2 lines
Documentation/git-cherry.txt +2 -0
+For details about how patches are compared, see git-patch-id.
+

Thanks.

In manual pages, "SEE ALSO" section is a more appropriate place to do this kind of thing.

Here's an improved patch.

Geoffrey

commit 2417df3ffc04e05c187a93ae58f620f2709ae950

Author: Geoffrey Irving <[email protected]>
Date:   Wed May 28 12:38:11 2008 -0700

doc: reference git-patch-id in git-cherry documentation

Documentation/git-cherry.txt +5 -0
index b0468aa..dbf8895 100644
@@ -56,6 +56,11 @@ OPTIONS
 <limit>::
        Do not report commits up to (and including) limit.
 
+See Also
+--------
+'git-patch-id(1)'::
+       The mechanism git-cherry uses to compare changesets.
+
 Author
 ------
 Written by Junio C Hamano <[email protected]>
#7 lore raw
Quoted 4 lines · Geoffrey Irving
Quoted 2 lines

In manual pages, "SEE ALSO" section is a more appropriate place to do this kind of thing.

Here's an improved patch.

The usual way to include a cover letter in a patch is either:

Subject: [PATCH] commit message subject

commit message

---
your cover letter

diffstat + diff

or (and I often use this in a reply where it makes sense to read the cover letter first):

Subject: Re: your mail

cover letter

-- >8 -- (any visual separator that is _not_ "---") commit message subject

commit message

---
diffstat + diff

In the second case, I believe Junio just manually deletes everything above the separator.

Documentation/git-cherry.txt OPTIONS · line 63

Quoted 5 lines
Documentation/git-cherry.txt +5 -0
+See Also
+--------
+'git-patch-id(1)'::
+       The mechanism git-cherry uses to compare changesets.
+

This should be

linkgit:git-patch-id[1]::

which will turn it into the text you wrote for a manpage, or a link in the HTML version. Looks like we already have a few of the style you used that should probably be fixed, though.

-Peff

#8 lore raw
Quoted 3 lines · Jeff King

which will turn it into the text you wrote for a manpage, or a link in the HTML version. Looks like we already have a few of the style you used that should probably be fixed, though.

Actually, it looks like there is only one; patch is below. There are a few false positives in gitk.txt, but they point to projects outside of core git (like qgit, gitview, and tig), and so must be left as straight text.

-- >8 --
doc/git-gui: make gitk "see also" a link

Even though git-gui and gitk are both maintained separately, the documentation is part of core git, and thus it makes sense to use the linkgit macro to create an href in the HTML documentation.

---
 Documentation/git-gui.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Documentation/git-gui.txt +1 -1
index 6d6cd5d..cf2541f 100644
@@ -81,7 +81,7 @@ git gui browser maint::
 
 See Also
 --------
-'gitk(1)'::
+linkgit:gitk[1]::
 	The git repository browser.  Shows branches, commit history
 	and file differences.  gitk is the utility started by
 	git-gui's Repository Visualize actions.
Signature · 1 line
1.5.6.rc0.143.ge5cbe0
#9 lore raw
Quoted 15 lines · Jeff King

doc/git-gui: make gitk "see also" a link

Even though git-gui and gitk are both maintained separately, the documentation is part of core git, and thus it makes sense to use the linkgit macro to create an href in the HTML documentation.

---
 Documentation/git-gui.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Documentation/git-gui.txt +0 -0
index 6d6cd5d..cf2541f 100644

Documentation/git-gui.txt git gui browser maint:: · line 87

Quoted 8 lines
Documentation/git-gui.txt +1 -1
@@ -81,7 +81,7 @@ git gui browser maint::
 
 See Also
 --------
-'gitk(1)'::
+linkgit:gitk[1]::
 	The git repository browser.  Shows branches, commit history
 	and file differences.  gitk is the utility started by
 	git-gui's Repository Visualize actions.

Hmm.

First a bit offtopic to avoid duplicated work. Please nobody waste your time sending s/See Also/SEE ALSO/ clean-up patch. I've done that already.

Now, I do not think it is customary to say anything but the name of the manual page if you refer to one in SEE ALSO section. I am wondering if we would want to remove the three-liner for consistency (but haven't done so, neither the short description of qgit and others in gitk manual page is gone yet).

 Documentation/git-gui.txt |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
Documentation/git-gui.txt +2 -5
index 6d6cd5d..cea8f8a 100644
@@ -79,12 +79,9 @@ git gui browser maint::
 	selected in the browser can be viewed with the internal
 	blame viewer.
 
-See Also
+SEE ALSO
 --------
-'gitk(1)'::
-	The git repository browser.  Shows branches, commit history
-	and file differences.  gitk is the utility started by
-	git-gui's Repository Visualize actions.
+linkgit:gitk[1]
 
 Other
 -----
#10 lore raw
Quoted 2 lines · Junio C Hamano

First a bit offtopic to avoid duplicated work. Please nobody waste your time sending s/See Also/SEE ALSO/ clean-up patch. I've done that already.

It is much more widespread than that. We are very inconsistent with section title capitalization. For man pages, it doesn't matter; asciidoc makes them all upper case. However, they end up inconsistent in the html versions. So if we care about this, then probably everything should be fixed.

You can get a rough idea with:

  $ cd Documentation && perl -ne '
      print "$ARGV:$last" if
        /^-+$/ &&
        length == length($last) &&
        $last =~ /[a-z]/;
      $last = $_;
    ' git-*.txt
Quoted 5 lines

Now, I do not think it is customary to say anything but the name of the manual page if you refer to one in SEE ALSO section. I am wondering if we would want to remove the three-liner for consistency (but haven't done so, neither the short description of qgit and others in gitk manual page is gone yet).

It isn't how most of the pages are, but I think it is actually helpful. And it's not as if "SEE ALSO" contents are supposed to be machine parsable.

Though if the _reason_ that one needs to "see also" is not obvious, perhaps it is better as part of the text of a different section (OTOH, I think Geoffrey's patch was in response to your request to put it in the "SEE ALSO").

-Peff

#11 lore raw

PATCH 1/1 Documentation: git-cherry uses git-patch-id

In reply to Geoffrey Irving
Quoted 8 lines · Geoffrey Irving
Quoted 4 lines · Junio C Hamano

Thanks.

In manual pages, "SEE ALSO" section is a more appropriate place to do this kind of thing.

Here's an improved patch.

Thanks, I'll do this instead...

-- >8 --
Geoffrey Irving noticed that git-cherry talks about comparing commits without hinting how they are compared.

---
 Documentation/git-cherry.txt |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
Documentation/git-cherry.txt +6 -0
index b0468aa..d8e0a5b 100644
@@ -13,6 +13,8 @@ DESCRIPTION
 -----------
 The changeset (or "diff") of each commit between the fork-point and <head>
 is compared against each commit between the fork-point and <upstream>.
+The commits are compared with their 'patch id', obtained from linkgit:git-patch-id[1]
+program.
 
 Every commit that doesn't exist in the <upstream> branch
 has its id (sha1) reported, prefixed by a symbol.  The ones that have
@@ -56,6 +58,10 @@ OPTIONS
 <limit>::
 	Do not report commits up to (and including) limit.
 
+SEE ALSO
+--------
+linkgit:git-patch-id[1]
+
 Author
 ------
 Written by Junio C Hamano <[email protected]>
Signature · 1 line
1.5.6.rc0.43.g823ea
#12 lore raw

Re: [PATCH] Documentation: git-cherry uses git-patch-id

Quoted 4 lines · Junio C Hamano
Quoted 2 lines · Geoffrey Irving

On Wed, May 28, 2008 at 1:46 PM, Junio C Hamano <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Thanks.

In manual pages, "SEE ALSO" section is a more appropriate place to do this kind of thing.

Here's an improved patch.

Thanks, I'll do this instead...

Thanks!

Incidentally, my original source of confusion was not understanding the order of arguments of git-cherry. Everything works fine once I use the correct order.

Geoffrey