# git cherry-pick before archive

11 messages from 2008-07-11 to 2008-07-11. Participants: Denis Bueno, Johannes Schindelin, Miklos Vajna, Junio C Hamano.
Thread: https://gitlist.dev/t/14409

## Denis Bueno, 2008-07-11 15:46

Subject: git cherry-pick before archive
Message-ID: <6dbd4d000807110846m2921ddb9r88eb3986762b8f81@mail.gmail.com>
URL: https://gitlist.dev/e/6dbd4d000807110846m2921ddb9r88eb3986762b8f81%40mail.gmail.com

```
Hi all,

I'm trying to use git archive to create a kind of "release" tarball of
my source.  I've got a patch (a commit) that I'd like to apply to the
tree before I call git archive on HEAD.  Currently my command is:

    git archive --format=tar --prefix=pfx/ HEAD | gzip > prj.tgz

If I were to actually modify my tree & history, I'd change the command to:

    git cherry-pick 97a1235ce674f7cf4df3129cd0ab1ae0793db392
    git archive --format=tar --prefix=pfx/ HEAD | gzip > prj.tgz
    git reset --hard HEAD^

But I'd rather not modify my history, if it's possible.  (This will
create a bunch of dangling commit objects over time, no?)

-- 
 Denis

```

## Johannes Schindelin, 2008-07-11 15:51

Subject: Re: git cherry-pick before archive
Message-ID: <alpine.DEB.1.00.0807111649290.8950@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807111649290.8950%40racer
In-Reply-To: <6dbd4d000807110846m2921ddb9r88eb3986762b8f81@mail.gmail.com>

```
Hi,

On Fri, 11 Jul 2008, Denis Bueno wrote:

> I'm trying to use git archive to create a kind of "release" tarball of
> my source.  I've got a patch (a commit) that I'd like to apply to the
> tree before I call git archive on HEAD.  Currently my command is:
> 
>     git archive --format=tar --prefix=pfx/ HEAD | gzip > prj.tgz
> 
> If I were to actually modify my tree & history, I'd change the command to:
> 
>     git cherry-pick 97a1235ce674f7cf4df3129cd0ab1ae0793db392
>     git archive --format=tar --prefix=pfx/ HEAD | gzip > prj.tgz
>     git reset --hard HEAD^
> 
> But I'd rather not modify my history, if it's possible.  (This will
> create a bunch of dangling commit objects over time, no?)

$ git cherry-pick -n <bla>
$ git archive --format=tar --prefix=pfx/ $(git write-tree) | gzip > prj.tgz
$ git reset

Hth,
Dscho

```

## Denis Bueno, 2008-07-11 16:09

Subject: Re: git cherry-pick before archive
Message-ID: <6dbd4d000807110909n1ced22eeraef45af441c20cca@mail.gmail.com>
URL: https://gitlist.dev/e/6dbd4d000807110909n1ced22eeraef45af441c20cca%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0807111649290.8950@racer>

```
On Fri, Jul 11, 2008 at 11:51, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> $ git cherry-pick -n <bla>
> $ git archive --format=tar --prefix=pfx/ $(git write-tree) | gzip > prj.tgz
> $ git reset

Thank you!  This is much better.  The only thing that could improve it
is by some way to "un-cherry-pick" the applied change (so that after
"git reset" there are no local modifications to the file(s) changed by
cherry-picking <bla>).

Is there an easy way to invert a patch to undo the change the original
patch introduced?


-- 
 Denis

```

## Miklos Vajna, 2008-07-11 16:11

Subject: Re: git cherry-pick before archive
Message-ID: <20080711161158.GD10347@genesis.frugalware.org>
URL: https://gitlist.dev/e/20080711161158.GD10347%40genesis.frugalware.org
In-Reply-To: <6dbd4d000807110909n1ced22eeraef45af441c20cca@mail.gmail.com>

```
On Fri, Jul 11, 2008 at 12:09:02PM -0400, Denis Bueno <dbueno@gmail.com> wrote:
> On Fri, Jul 11, 2008 at 11:51, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> > $ git cherry-pick -n <bla>
> > $ git archive --format=tar --prefix=pfx/ $(git write-tree) | gzip > prj.tgz
> > $ git reset

I guess he wanted to write 'git reset --hard' here ;-)

> 
> Thank you!  This is much better.  The only thing that could improve it
> is by some way to "un-cherry-pick" the applied change (so that after
> "git reset" there are no local modifications to the file(s) changed by
> cherry-picking <bla>).
> 
> Is there an easy way to invert a patch to undo the change the original
> patch introduced?

git show <commit> | git apply -R?

```

## Denis Bueno, 2008-07-11 16:18

Subject: Re: git cherry-pick before archive
Message-ID: <6dbd4d000807110918s1187abeaye6f249ff60b650fb@mail.gmail.com>
URL: https://gitlist.dev/e/6dbd4d000807110918s1187abeaye6f249ff60b650fb%40mail.gmail.com
In-Reply-To: <20080711161158.GD10347@genesis.frugalware.org>

```
On Fri, Jul 11, 2008 at 12:11, Miklos Vajna <vmiklos@frugalware.org> wrote:
> On Fri, Jul 11, 2008 at 12:09:02PM -0400, Denis Bueno <dbueno@gmail.com> wrote:
>> On Fri, Jul 11, 2008 at 11:51, Johannes Schindelin
>> <Johannes.Schindelin@gmx.de> wrote:
>> > $ git cherry-pick -n <bla>
>> > $ git archive --format=tar --prefix=pfx/ $(git write-tree) | gzip > prj.tgz
>> > $ git reset
>
> I guess he wanted to write 'git reset --hard' here ;-)

But that will undo local modifications to any uncommitted files, not
just those affected by the cherry-pick.  I don't want to do that.

>> Thank you!  This is much better.  The only thing that could improve it
>> is by some way to "un-cherry-pick" the applied change (so that after
>> "git reset" there are no local modifications to the file(s) changed by
>> cherry-picking <bla>).
>>
>> Is there an easy way to invert a patch to undo the change the original
>> patch introduced?
>
> git show <commit> | git apply -R?

Brilliant!  Thanks.  I didn't know about apply (or show for that matter ....).

-- 
 Denis

```

## Johannes Schindelin, 2008-07-11 18:25

Subject: Re: git cherry-pick before archive
Message-ID: <alpine.DEB.1.00.0807111924180.8950@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807111924180.8950%40racer
In-Reply-To: <20080711161158.GD10347@genesis.frugalware.org>

```
Hi,

On Fri, 11 Jul 2008, Miklos Vajna wrote:

> On Fri, Jul 11, 2008 at 12:09:02PM -0400, Denis Bueno <dbueno@gmail.com> wrote:
> > On Fri, Jul 11, 2008 at 11:51, Johannes Schindelin
> > <Johannes.Schindelin@gmx.de> wrote:
> > > $ git cherry-pick -n <bla>
> > > $ git archive --format=tar --prefix=pfx/ $(git write-tree) | gzip > prj.tgz
> > > $ git reset
> 
> I guess he wanted to write 'git reset --hard' here ;-)

He did not ;-)  "git reset" resets only the index, which is what I wanted.

Anyway, back to Denis' question: I could imagine (haven't tested, 
thought), that "git revert -n <the-same-commit>" would undo the "git 
cherry-pick -n".

Please test and report back,
Dscho

```

## Denis Bueno, 2008-07-11 18:28

Subject: Re: git cherry-pick before archive
Message-ID: <6dbd4d000807111128l4721113dh3713bc7abd3d837e@mail.gmail.com>
URL: https://gitlist.dev/e/6dbd4d000807111128l4721113dh3713bc7abd3d837e%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0807111924180.8950@racer>

```
On Fri, Jul 11, 2008 at 14:25, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> Anyway, back to Denis' question: I could imagine (haven't tested,
> thought), that "git revert -n <the-same-commit>" would undo the "git
> cherry-pick -n".

So I need to be able to maintain the patch that is applied to the tree
before archiving, so instead of a commit ID, I'm now using a patch
file, and the sequence of actions is like so:

    $ <assume index is clean>
    $ git apply --cached patchfile || exit 1
    $ git archive --format=tar --prefix=pfx/ $(git write-tree) \
          | gzip > prj.tgz
    $ git reset

This way I don't even need to reverse-apply the patch, because I never
touch the working copy.  Of course, this can't be done in this way in
any other revision control system, because they don't have an index.

-- 
 Denis

```

## Johannes Schindelin, 2008-07-11 18:46

Subject: Re: git cherry-pick before archive
Message-ID: <alpine.DEB.1.00.0807111944000.8950@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807111944000.8950%40racer
In-Reply-To: <6dbd4d000807111128l4721113dh3713bc7abd3d837e@mail.gmail.com>

```
Hi,

On Fri, 11 Jul 2008, Denis Bueno wrote:

> On Fri, Jul 11, 2008 at 14:25, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> > Anyway, back to Denis' question: I could imagine (haven't tested,
> > thought), that "git revert -n <the-same-commit>" would undo the "git
> > cherry-pick -n".
> 
> So I need to be able to maintain the patch that is applied to the tree
> before archiving, so instead of a commit ID, I'm now using a patch
> file, and the sequence of actions is like so:
> 
>     $ <assume index is clean>
>     $ git apply --cached patchfile || exit 1
>     $ git archive --format=tar --prefix=pfx/ $(git write-tree) \
>           | gzip > prj.tgz
>     $ git reset
> 
> This way I don't even need to reverse-apply the patch, because I never
> touch the working copy.  Of course, this can't be done in this way in
> any other revision control system, because they don't have an index.

Well, they have.  They just do not expose it.

BTW in your case, I would suggest this:

	INDEX_FILE=.git/bla git read-tree HEAD &&
	INDEX_FILE=.git/bla git apply --cached patchfile &&
	INDEX_FILE=.git/bla git archive [...] &&
	rm .git/bla

IOW: Just use a temporary index for your work.

Ciao,
Dscho

```

## Denis Bueno, 2008-07-11 18:49

Subject: Re: git cherry-pick before archive
Message-ID: <6dbd4d000807111149s4fb661cak9fac152864260901@mail.gmail.com>
URL: https://gitlist.dev/e/6dbd4d000807111149s4fb661cak9fac152864260901%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0807111944000.8950@racer>

```
On Fri, Jul 11, 2008 at 14:46, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> BTW in your case, I would suggest this:
>
>        INDEX_FILE=.git/bla git read-tree HEAD &&
>        INDEX_FILE=.git/bla git apply --cached patchfile &&
>        INDEX_FILE=.git/bla git archive [...] &&
>        rm .git/bla
>
> IOW: Just use a temporary index for your work.

What is the rationale?  So I can relieve the assumption that the index is clean?

-- 
 Denis

```

## Johannes Schindelin, 2008-07-11 18:53

Subject: Re: git cherry-pick before archive
Message-ID: <alpine.DEB.1.00.0807111950540.8950@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807111950540.8950%40racer
In-Reply-To: <6dbd4d000807111149s4fb661cak9fac152864260901@mail.gmail.com>

```
Hi,

On Fri, 11 Jul 2008, Denis Bueno wrote:

> On Fri, Jul 11, 2008 at 14:46, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> > BTW in your case, I would suggest this:
> >
> >        INDEX_FILE=.git/bla git read-tree HEAD &&
> >        INDEX_FILE=.git/bla git apply --cached patchfile &&
> >        INDEX_FILE=.git/bla git archive [...] &&
> >        rm .git/bla
> >
> > IOW: Just use a temporary index for your work.
> 
> What is the rationale?  So I can relieve the assumption that the index 
> is clean?

Not completely.

It will just leave the current index alone, ignoring the changes within 
it.  It will also avoid having to update the index several times.

IMO it is just the thing you should do here: you do not want to stage 
anything for commit, so keep .git/index as-is, and use a temporary staging 
area instead.

It also avoids the need to "undo" things that might not be easily undone: 
if your patch contains stuff that was partly in the index, but 
uncommitted, neither "git reset" nor "git revert -n" will do what you 
want.

Ciao,
Dscho

```

## Junio C Hamano, 2008-07-11 22:18

Subject: Re: git cherry-pick before archive
Message-ID: <7vzloohxo1.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzloohxo1.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <alpine.DEB.1.00.0807111649290.8950@racer>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Hi,
>
> On Fri, 11 Jul 2008, Denis Bueno wrote:
>
>> I'm trying to use git archive to create a kind of "release" tarball of
>> my source.  I've got a patch (a commit) that I'd like to apply to the
>> tree before I call git archive on HEAD.  Currently my command is:
>> 
>>     git archive --format=tar --prefix=pfx/ HEAD | gzip > prj.tgz
>> 
>> If I were to actually modify my tree & history, I'd change the command to:
>> 
>>     git cherry-pick 97a1235ce674f7cf4df3129cd0ab1ae0793db392
>>     git archive --format=tar --prefix=pfx/ HEAD | gzip > prj.tgz
>>     git reset --hard HEAD^
>> 
>> But I'd rather not modify my history, if it's possible.  (This will
>> create a bunch of dangling commit objects over time, no?)
>
> $ git cherry-pick -n <bla>
> $ git archive --format=tar --prefix=pfx/ $(git write-tree) | gzip > prj.tgz
> $ git reset

That will create a bunch of dangling tree objects over time, yes.

```
