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

Re: [Bug] Stashing during merge loses MERGING state

From
Jeff King <peff@peff.net>
Date
Mar 11, 2021, 19:25 UTC
Message-ID
<YEpusE7ZIE5RgOws@coredump.intra.peff.net>
In-Reply-To
<875z1xwznd.fsf@gnu.org>
On Thu, Mar 11, 2021 at 03:00:58PM +0100, Tassilo Horn wrote:
Show 19 quoted lines
> Here is a simple recipe with a publicly available repo:
> 
> ```sh
> git clone https://github.com/magit/magit.git
> # Current master is 4735b9254105eb7dd538f979d8b4c6ab96b827b9
> cd magit
> git merge origin/km/reshelve-rewrite # currently 0073bff21c826a57a4b48076074bdbba092d4b67
> # Conflict in magit-extras.el
> git add lisp/magit-extras.el
> git stash
> # The MERGING state is gone
> git stash pop
> # And it won't come back, so when I commit now, my "merge" has just
> # one parent.
> ```
> 
> What did you expect to happen? (Expected behavior)
> 
> I expected that stashing during a merge will keep the MERGING state.

Thanks for providing a clear recipe and expectation. However, I think Git is working here as intended. The MERGE_HEAD file (which is how "git status", the prompt, etc figure out that we're in the middle of a merge) is cleaned up when stash runs "git reset --hard" under the hood.

However, I don't think we would want to _not_ clear that file. The conflicted merge placed some changes into the index and working tree representing what happened on the branch you're merging in. Then making the stash (and the reset of the working tree) removes those changes. If we were to leave MERGE_HEAD in place and you ran "git commit", then it would create a merge commit that claims to have incorporated everything from the other branch, but has quietly dropped those changes as part of the merge resolution.

> Or that popping the stash again would also restore the MERGING state.

This would make more sense: the stash records that part of the state, and then we make it available again later when the stash is applied. However, that feature doesn't exist yet.

I can't offhand think of a reason it couldn't be implemented. It's possible that it would mess with somebody else's workflow (e.g., they think it's useful to stash some changes independent of the merging state, and then apply it later, perhaps while replaying the same or a similar merge). So it might need to be tied to a command-line option or similar.

-Peff
Previous: Tassilo HornNext: Tassilo Horn
Message 2 of 9 in “[Bug] Stashing during merge loses MERGING state”
  1. Tassilo HornMar 11, 2021
  2. Jeff KingMar 11, 2021
  3. Tassilo HornMar 11, 2021
  4. Phil HordMar 12, 2021
  5. Junio C HamanoMar 12, 2021
  6. Elijah NewrenMar 12, 2021
  7. Chris TorekMar 12, 2021
  8. Elijah NewrenMar 12, 2021
  9. Elijah NewrenMar 12, 2021

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.