# Behavior of stash apply vs merge

5 messages from 2013-01-27 to 2013-01-27. Participants: Robin Rosenberg, Junio C Hamano.
Thread: https://gitlist.dev/t/32741

## Robin Rosenberg, 2013-01-27 11:35

Subject: Behavior of stash apply vs merge
Message-ID: <61173190.1700449.1359286556865.JavaMail.root@dewire.com>
URL: https://gitlist.dev/e/61173190.1700449.1359286556865.JavaMail.root%40dewire.com
In-Reply-To: <1192924141.1697155.1359285809347.JavaMail.root@dewire.com>

```
Hi,

What good reason is it that 'git stash apply' gives hairy conflict markers, while 'git merge stash' does not. No renames involved.

-- robin

```

## Junio C Hamano, 2013-01-27 17:57

Subject: Re: Behavior of stash apply vs merge
Message-ID: <7vvcaiwltj.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vvcaiwltj.fsf%40alter.siamese.dyndns.org
In-Reply-To: <61173190.1700449.1359286556865.JavaMail.root@dewire.com>

```
Robin Rosenberg <robin.rosenberg@dewire.com> writes:

> What good reason is it that 'git stash apply' gives hairy conflict
> markers, while 'git merge stash' does not. No renames involved.

"git merge stash" is nonsensical and would do a vastly different
thing compared to "git stash apply" depending on where you created
the stash and where you are attempting to run that operation.

Imagine you started fixing a bug while on the 'master' branch,
realized that the fix equally well applies to your 'maint' branch.
You would do "git stash" followed by "git checkout maint".

A sane person would do "git stash apply" at this point.  It applies
the difference between the 'master' you were working on and your WIP
on top of your 'maint'.

"git merge stash" is entirely different.  The history leading to a
stash looks like this:

                   I
                  / \
      ---o---o---B---W

where

	B is the commit you were working on (i.e. 'master');
	I records the state of the index;
	W records the state of the working tree.

and "stash" refers to W.

Think what commit B is in this example and the reason why you should
never ever do "git merge stash" will become apparent.  By merging W
into 'maint', you would be pulling the entire history between
'maint' and 'master' to the result.

```

## Robin Rosenberg, 2013-01-27 19:09

Subject: Re: Behavior of stash apply vs merge
Message-ID: <2043716001.1806075.1359313796808.JavaMail.root@dewire.com>
URL: https://gitlist.dev/e/2043716001.1806075.1359313796808.JavaMail.root%40dewire.com
In-Reply-To: <7vvcaiwltj.fsf@alter.siamese.dyndns.org>

```
Thanks. Feeling a bit studid now.

I was actually thinking about using merge to implement stash apply
in JGit. What we have is broken so I tried using merge to implement
it and them compared to git merge --no-commit.. FAIL.

The main difference is of course that I set the merge base to
stash^1, which is obviously not what my question was about.

-- robin

```

## Junio C Hamano, 2013-01-27 19:12

Subject: Re: Behavior of stash apply vs merge
Message-ID: <7vfw1mwibu.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vfw1mwibu.fsf%40alter.siamese.dyndns.org
In-Reply-To: <2043716001.1806075.1359313796808.JavaMail.root@dewire.com>

```
Robin Rosenberg <robin.rosenberg@dewire.com> writes:

> Thanks. Feeling a bit studid now.
>
> I was actually thinking about using merge to implement stash apply
> in JGit. What we have is broken so I tried using merge to implement
> it and them compared to git merge --no-commit.. FAIL.

Do you have "cherry-pick"?

In short, "stash apply" is a "cherry-pick" in disguise.

```

## Robin Rosenberg, 2013-01-27 19:51

Subject: Re: Behavior of stash apply vs merge
Message-ID: <35452020.1815583.1359316269106.JavaMail.root@dewire.com>
URL: https://gitlist.dev/e/35452020.1815583.1359316269106.JavaMail.root%40dewire.com
In-Reply-To: <7vfw1mwibu.fsf@alter.siamese.dyndns.org>

```


----- Ursprungligt meddelande -----
> Robin Rosenberg <robin.rosenberg@dewire.com> writes:
> 
> > Thanks. Feeling a bit studid now.
> >
> > I was actually thinking about using merge to implement stash apply
> > in JGit. What we have is broken so I tried using merge to implement
> > it and them compared to git merge --no-commit.. FAIL.
> 
> Do you have "cherry-pick"?
>
> In short, "stash apply" is a "cherry-pick" in disguise.

Yes, that's what I did. Thanks for confirming this. One for the working
tree and if that succeeds I do another one to restore the index if requested.

-- robin

```
