{"thread":{"id":"12791","subject":"Recording cherry-picked commits","startedAt":"2008-03-21T12:33:11Z","lastAt":"2008-03-23T14:12:38Z","messageCount":8,"participants":["Jean-Baptiste Quenot","Rafael Garcia-Suarez","Junio C Hamano","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"72588","messageId":"ae63f8b50803210533n12645fb3w9a8be601c4cc394@mail.gmail.com","threadId":"12791","inReplyTo":null,"subject":"Recording cherry-picked commits","fromName":"Jean-Baptiste Quenot","fromEmail":"jbq@caraldi.com","sentAt":"2008-03-21T12:33:11Z","receivedAt":"2008-03-21T12:33:11Z","isPatch":false,"sender":{"key":"jbq@caraldi.com","avatar":null},"body":"Hi there,\n\nCherry-picking is great with Git, both with git-cherry-pick and\ngit-cherry.   I use them to pick commits from my development branch to\nmy stable maintenance branch that goes to production.\n\nBut when a particular commit is slightly different between the two\nbranches (due to eg a conflict resolution in my stable branch), then\ngit-cherry still lists the commit as only present in the development\nbranch.  This is a feature, as documented in the man page, because\ngit-cherry compares the changeset rather than the commit id.\n\nSo I'm wondering if there's a way to record the commit ID as being\nalready picked from the development branch to the stable branch, so\nthat it's not listed again when I provide the same arguments to\ncherry-pick.  I was used to this kind of feature with svnmerge, a\nwrapper script around svn that records cherry-picked commits in a\nSubversion property called svnmerge-integrated on the root directory.\nBut with Git, what is the best practice for knowing which commits you\nalready picked?\n\nIdeally, the set of already-picked commits would be versioned in the\nGit repo itself, so that other developers can watch what commits are\navailable to pick as well.\n\nThanks in advance,\n-- \nJean-Baptiste Quenot\nhttp://caraldi.com/jbq/blog/\n"},{"id":"72675","messageId":"ae63f8b50803220937k78571fbdl1eeb60966ec7aa40@mail.gmail.com","threadId":"12791","inReplyTo":"ae63f8b50803210533n12645fb3w9a8be601c4cc394@mail.gmail.com","subject":"Re: Recording cherry-picked commits","fromName":"Jean-Baptiste Quenot","fromEmail":"jbq@caraldi.com","sentAt":"2008-03-22T16:37:33Z","receivedAt":"2008-03-22T16:37:33Z","isPatch":false,"sender":{"key":"jbq@caraldi.com","avatar":null},"body":"What about using a hidden \".gitcherry\" file in the current branch to\nstore the commits that have been applied?  With the simple shell\nscripts below I'm able to achieve the same effect as svnmerge:\n\n\nWrapper around git-cherry-pick:\n------------------------------------------------------------------------\n#! /bin/sh -e\n\n# Write the commit in .gitcherry, stage .gitcherry for commit and call\n# git-cherry-pick.  If a conflict occurs, resolve it and invoke this script with\n# --continue, in order to commit with the original author and commit message\n\nif test \"$1\" = \"--continue\" ; then\n    cont=1\n    commit=$(tail -1 .gitcherry)\nelse\n    cont=0\n    commit=$1\nfi\n\nif test $cont = 0 ; then\n    echo $commit >> .gitcherry\n    git add .gitcherry\n    git cherry-pick $commit\nelse\n    git commit -c $commit\nfi\n-------------------------------------------------------------------------\n\n\nWrapper around git-cherry:\n------------------------------------------------------------------------\n#! /bin/sh -e\n\n# List all commits with git-cherry and exclude all the ones that are specified\n# in .gitcherry.  For each commit, invoke 'git show' to print the commit message\n\nfor commit in $(git-cherry $* | sed -ne 's/^+ //p' | grep -v -f .gitcherry) ; do\n    git show -s --pretty=format:\"%H %s\" $commit\ndone\n------------------------------------------------------------------------\n\nWDYT?\n-- \nJean-Baptiste Quenot\nhttp://caraldi.com/jbq/blog/\n"},{"id":"72711","messageId":"b77c1dce0803221548x3250cb90taa9a9d53464f7ea7@mail.gmail.com","threadId":"12791","inReplyTo":"ae63f8b50803220937k78571fbdl1eeb60966ec7aa40@mail.gmail.com","subject":"Re: Recording cherry-picked commits","fromName":"Rafael Garcia-Suarez","fromEmail":"rgarciasuarez@gmail.com","sentAt":"2008-03-22T22:48:32Z","receivedAt":"2008-03-22T22:48:32Z","isPatch":false,"sender":{"key":"rgarciasuarez@gmail.com","avatar":null},"body":"On 22/03/2008, Jean-Baptiste Quenot <jbq@caraldi.com> wrote:\n> What about using a hidden \".gitcherry\" file in the current branch to\n>  store the commits that have been applied?  With the simple shell\n>  scripts below I'm able to achieve the same effect as svnmerge:\n\n(.gitcherry should really be at the root of the git repository, not in\nthe current directory)\n\nWhat happens to .gitcherry across merges ? I think your solution isn't\nrobust enough.\n\nHere's an alternate idea: store the original sha1 in the commit\nmessage, via a custom header (something like X-Cherry-Picked-From) at\nleast in case of conflict, and have git-cherry recognize it.\n\n(I have the same problem as you, by the way, and would really like to\nsee it solved one way or another.)\n"},{"id":"72712","messageId":"7veja2gts9.fsf@gitster.siamese.dyndns.org","threadId":"12791","inReplyTo":"b77c1dce0803221548x3250cb90taa9a9d53464f7ea7@mail.gmail.com","subject":"Re: Recording cherry-picked commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-23T00:37:10Z","receivedAt":"2008-03-23T00:37:10Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Rafael Garcia-Suarez\" <rgarciasuarez@gmail.com> writes:\n\n> Here's an alternate idea: store the original sha1 in the commit\n> message, via a custom header (something like X-Cherry-Picked-From) at\n> least in case of conflict, and have git-cherry recognize it.\n>\n> (I have the same problem as you, by the way, and would really like to\n> see it solved one way or another.)\n\n\"-x\"?\n"},{"id":"72733","messageId":"ae63f8b50803230407u7062586dy26fab7d98090efb9@mail.gmail.com","threadId":"12791","inReplyTo":"b77c1dce0803221548x3250cb90taa9a9d53464f7ea7@mail.gmail.com","subject":"Re: Recording cherry-picked commits","fromName":"Jean-Baptiste Quenot","fromEmail":"jbq@caraldi.com","sentAt":"2008-03-23T11:07:52Z","receivedAt":"2008-03-23T11:07:52Z","isPatch":false,"sender":{"key":"jbq@caraldi.com","avatar":null},"body":"2008/3/22, Rafael Garcia-Suarez <rgarciasuarez@gmail.com>:\n> On 22/03/2008, Jean-Baptiste Quenot <jbq@caraldi.com> wrote:\n>  > What about using a hidden \".gitcherry\" file in the current branch to\n>  >  store the commits that have been applied?  With the simple shell\n>  >  scripts below I'm able to achieve the same effect as svnmerge:\n>\n> (.gitcherry should really be at the root of the git repository, not in\n>  the current directory)\n\nYes that's what I meant.  Usually I'm always at the root when I'm\ncherry-picking changes but you're right the script could be improved\nin this regard.  Is there a trick to find the root repository\ndirectory?\n\n>  What happens to .gitcherry across merges ?  I think your solution isn't robust\n> enough.\n\nThe .gitcherry is merged like any other file.  I'm just trying to\nmimic svnmerge here, not to reinvent anything.  As Git does not have\nfile metadata, I'm using a plain text file to achieve this.\n\n>  Here's an alternate idea: store the original sha1 in the commit\n>  message, via a custom header (something like X-Cherry-Picked-From) at\n>  least in case of conflict, and have git-cherry recognize it.\n\nI like your idea of filtering on commit messages, that makes sense and\nit voids the use of .gitcherry, and thus better preserves the diffs.\n\nHere is the updated git-cherry-pick wrapper.  Note that we repeat the\ncommit log in the message, and we're loosing the author information.\nKeeping the author would require to change git-commit to allow\ncombining -C and -F.  Also it seems that -C and -t are incompatible,\nalthough git-commit does not error out.\n\nJunio suggests to use git-cherry's -x flag, but it is not written upon\nconflict, so it's useless for the current usecase about properly\nhandling conflicts during cherry-picking.\n\n------------------------------------------------------------------------\n#! /bin/sh -e\n\n# Record the commit id in .git/CHERRY_COMMIT, and call git-cherry-pick without\n# actually committing.  If a conflict occurs, resolve it and invoke this script\n# with --continue.  The commit log is then fed to git commit.\n#\n# FIXME find the root repository directory\n\nif test \"$1\" = \"--continue\" ; then\n    cont=1\n    commit=$(cat .git/CHERRY_COMMIT)\nelse\n    cont=0\n    commit=$1\nfi\n\nif test $cont = 0 ; then\n    echo $commit > .git/CHERRY_COMMIT\n    git cherry-pick -n $commit\nfi\n\ngit log -1 $commit | git commit -F -\nrm -f .git/CHERRY_COMMIT\n------------------------------------------------------------------------\n\n\nAnd the updated git-cherry wrapper:\n------------------------------------------------------------------------\n#! /bin/sh -e\n\n# List all commits with git-cherry and exclude all the ones that are already\n# part of the change log of the current branch.  For each available commit,\n# invoke 'git show' to print the commit message.\n\ntempfile=$(tempfile -p $(basename $0))\ngit log --pretty=format:%s | sed -ne 's/^commit\n\\([a-z0-9]\\{40\\}\\)$/\\1/p' > $tempfile\n\nfor commit in $(git-cherry $* | sed -ne 's/^+ //p' | grep -v -f $tempfile) ; do\n    git show -s --pretty=format:\"%H %s\" $commit\ndone\n\nrm -f $tempfile\n------------------------------------------------------------------------\n\nCheers,\n-- \nJean-Baptiste Quenot\nhttp://caraldi.com/jbq/blog/\n"},{"id":"72736","messageId":"alpine.LSU.1.00.0803231309370.4353@racer.site","threadId":"12791","inReplyTo":"ae63f8b50803230407u7062586dy26fab7d98090efb9@mail.gmail.com","subject":"Re: Recording cherry-picked commits","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-23T12:11:59Z","receivedAt":"2008-03-23T12:11:59Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 23 Mar 2008, Jean-Baptiste Quenot wrote:\n\n> 2008/3/22, Rafael Garcia-Suarez <rgarciasuarez@gmail.com>:\n> > On 22/03/2008, Jean-Baptiste Quenot <jbq@caraldi.com> wrote:\n> >  > What about using a hidden \".gitcherry\" file in the current branch \n> >  > to store the commits that have been applied?  With the simple shell \n> >  > scripts below I'm able to achieve the same effect as svnmerge:\n> >\n> > (.gitcherry should really be at the root of the git repository, not in \n> > the current directory)\n> \n> Yes that's what I meant.  Usually I'm always at the root when I'm \n> cherry-picking changes but you're right the script could be improved in \n> this regard.  Is there a trick to find the root repository directory?\n\nActually, you should not store it in the root of the working tree, but in \nthe git dir (because it should never be tracked!), and then you can make \nit non-hidden:\n\n\tfile=\"$(git rev-parse --git-dir)\"/cherry\n\n> > What happens to .gitcherry across merges ?  I think your solution \n> > isn't robust enough.\n> \n> The .gitcherry is merged like any other file.  I'm just trying to\n> mimic svnmerge here, not to reinvent anything.  As Git does not have\n> file metadata, I'm using a plain text file to achieve this.\n\nAh, I see, so you _want_ to track it.  I do not like this idea personally, \nbut then, I will not use .gitcherry anyway.\n\n\tfile=\"$(git rev-parse --show-cdup)\"/.gitcherry\n\nHth,\nDscho\n"},{"id":"72750","messageId":"b77c1dce0803230657i6d61abefg3b0ee7b42119927c@mail.gmail.com","threadId":"12791","inReplyTo":"alpine.LSU.1.00.0803231309370.4353@racer.site","subject":"Re: Recording cherry-picked commits","fromName":"Rafael Garcia-Suarez","fromEmail":"rgarciasuarez@gmail.com","sentAt":"2008-03-23T13:57:33Z","receivedAt":"2008-03-23T13:57:33Z","isPatch":false,"sender":{"key":"rgarciasuarez@gmail.com","avatar":null},"body":"On 23/03/2008, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Actually, you should not store it in the root of the working tree, but in\n>  the git dir (because it should never be tracked!), and then you can make\n>  it non-hidden:\n>\n>         file=\"$(git rev-parse --git-dir)\"/cherry\n\nBut this way, how can it be shared among several repositories?\n(without patching git-clone itself, that might be a solution.) The use\ncase being many commiters cherry-picking patches from a development\nbranch to a maintainance one.\n"},{"id":"72757","messageId":"alpine.LSU.1.00.0803231512110.4353@racer.site","threadId":"12791","inReplyTo":"b77c1dce0803230657i6d61abefg3b0ee7b42119927c@mail.gmail.com","subject":"Re: Recording cherry-picked commits","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-23T14:12:38Z","receivedAt":"2008-03-23T14:12:38Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 23 Mar 2008, Rafael Garcia-Suarez wrote:\n\n> On 23/03/2008, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > Actually, you should not store it in the root of the working tree, but in\n> >  the git dir (because it should never be tracked!), and then you can make\n> >  it non-hidden:\n> >\n> >         file=\"$(git rev-parse --git-dir)\"/cherry\n> \n> But this way, how can it be shared among several repositories?\n\nAs I said, I would not want it shared.  Or tracked.\n\nYou can still do what you want to, though.\n\nCiao,\nDscho\n"}]}