git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Recording cherry-picked commits

From
JQJean-Baptiste Quenot <jbq@caraldi.com>
Date
Mar 23, 2008, 11:07 UTC
Message-ID
<ae63f8b50803230407u7062586dy26fab7d98090efb9@mail.gmail.com>
In-Reply-To
<b77c1dce0803221548x3250cb90taa9a9d53464f7ea7@mail.gmail.com>
2008/3/22, Rafael Garcia-Suarez <rgarciasuarez@gmail.com>:
Show 7 quoted lines
> On 22/03/2008, Jean-Baptiste Quenot <jbq@caraldi.com> wrote:
>  > What about using a hidden ".gitcherry" file in the current branch to
>  >  store the commits that have been applied?  With the simple shell
>  >  scripts below I'm able to achieve the same effect as svnmerge:
>
> (.gitcherry should really be at the root of the git repository, not in
>  the current directory)

Yes that's what I meant. Usually I'm always at the root when I'm cherry-picking changes but you're right the script could be improved in this regard. Is there a trick to find the root repository directory?

>  What happens to .gitcherry across merges ?  I think your solution isn't robust
> enough.

The .gitcherry is merged like any other file. I'm just trying to mimic svnmerge here, not to reinvent anything. As Git does not have file metadata, I'm using a plain text file to achieve this.

>  Here's an alternate idea: store the original sha1 in the commit
>  message, via a custom header (something like X-Cherry-Picked-From) at
>  least in case of conflict, and have git-cherry recognize it.

I like your idea of filtering on commit messages, that makes sense and it voids the use of .gitcherry, and thus better preserves the diffs.

Here is the updated git-cherry-pick wrapper. Note that we repeat the commit log in the message, and we're loosing the author information. Keeping the author would require to change git-commit to allow combining -C and -F. Also it seems that -C and -t are incompatible, although git-commit does not error out.

Junio suggests to use git-cherry's -x flag, but it is not written upon conflict, so it's useless for the current usecase about properly handling conflicts during cherry-picking.

------------------------------------------------------------------------ #! /bin/sh -e

# Record the commit id in .git/CHERRY_COMMIT, and call git-cherry-pick without # actually committing. If a conflict occurs, resolve it and invoke this script # with --continue. The commit log is then fed to git commit. # # FIXME find the root repository directory

if test "$1" = "--continue" ; then
    cont=1
    commit=$(cat .git/CHERRY_COMMIT)
else
    cont=0
    commit=$1
fi
if test $cont = 0 ; then
    echo $commit > .git/CHERRY_COMMIT
    git cherry-pick -n $commit
fi

git log -1 $commit | git commit -F - rm -f .git/CHERRY_COMMIT ------------------------------------------------------------------------

And the updated git-cherry wrapper: ------------------------------------------------------------------------ #! /bin/sh -e

# List all commits with git-cherry and exclude all the ones that are already # part of the change log of the current branch. For each available commit, # invoke 'git show' to print the commit message.

tempfile=$(tempfile -p $(basename $0)) git log --pretty=format:%s | sed -ne 's/^commit \([a-z0-9]\{40\}\)$/\1/p' > $tempfile

for commit in $(git-cherry $* | sed -ne 's/^+ //p' | grep -v -f $tempfile) ; do
    git show -s --pretty=format:"%H %s" $commit
done

rm -f $tempfile ------------------------------------------------------------------------

Cheers,
-- 
Jean-Baptiste Quenot
http://caraldi.com/jbq/blog/
Previous: Junio C HamanoNext: Johannes Schindelin
Message 5 of 8 in “Recording cherry-picked commits”
  1. Jean-Baptiste QuenotMar 21, 2008
  2. Jean-Baptiste QuenotMar 22, 2008
  3. Rafael Garcia-SuarezMar 22, 2008
  4. Junio C HamanoMar 23, 2008
  5. Jean-Baptiste QuenotMar 23, 2008
  6. Johannes SchindelinMar 23, 2008
  7. Rafael Garcia-SuarezMar 23, 2008
  8. Johannes SchindelinMar 23, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.