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

Re: Behavior of stash apply vs merge

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 27, 2013, 17:57 UTC
Message-ID
<7vvcaiwltj.fsf@alter.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.

Previous: Robin RosenbergNext: Robin Rosenberg
Message 2 of 5 in “Behavior of stash apply vs merge”
  1. Robin RosenbergJan 27, 2013
  2. Junio C HamanoJan 27, 2013
  3. Robin RosenbergJan 27, 2013
  4. Junio C HamanoJan 27, 2013
  5. Robin RosenbergJan 27, 2013

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.