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

Re: [PATCH] Documentation: warn against merging in a dirty tree

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Sep 18, 2008, 15:15 UTC
Message-ID
<alpine.LFD.1.10.0809180804100.3337@nehalem.linux-foundation.org>
In-Reply-To
<32541b130809151653w27d7876fp35e0967d597ae2a9@mail.gmail.com>
On Mon, 15 Sep 2008, Avery Pennarun wrote:
> 
> But how do you abort a *failed* merge in a situation like Linus's
> example?  "git reset --hard HEAD" would destroy the unstaged Makefile
> change.

As mentioned by others, sometimes you are simply willing to take the risk. If I have dirty data, I still want to merge, because (a) my dirty data is a _convenience_ and (b) the risk of me having to do a "git reset" is pretty low anyway.

That said, it's actually kind of sad that we don't expose a real capability that the git plumbing does have. Namely

	git read-tree -u -m HEAD ORIG_HEAD

should do the right thing if you want to undo a merge (except it doesn't actually write ORIG_HEAD to be the new head: you could use "git reset" with --soft to do that, or just git update-ref).

So it _may_ be that something like
	[alias]
		undo = !git read-tree -u -m HEAD ORIG_HEAD && git reset --soft ORIG_HEAD
would actually give you "git undo". 

So we have the technology, and we just don't _expose_ that capability as a "git reset" thing. And we probably should. In fact, that is often the thing people really want, and it would have made sense to have it as the default action, but the initial design for "git reset" was literally as a way to get you out of a sticky corner when you had unmerged entries and you just wanted to throw away crud.

NOTE NOTE NOTE! I did _not_ test that the git read-tree thing actually works, or that the above alias does the right thing. Caveat testor! You're on your own. But I agree that we should have something like that.

		Linus
Previous: Junio C HamanoNext: Avery Pennarun
Message 7 of 17 in “[IRC/patches] Failed octopus merge does not clean up”
  1. Thomas RastSep 15, 2008
  2. Add test that checks octopus merge cleanupThomas Rast, Sep 15, 2008
  3. Documentation: warn against merging in a dirty treeThomas Rast, Sep 15, 2008
  4. Junio C HamanoSep 15, 2008
  5. Avery PennarunSep 15, 2008
  6. Junio C HamanoSep 16, 2008
  7. Linus TorvaldsSep 18, 2008
  8. Avery PennarunSep 18, 2008
  9. Junio C HamanoSep 19, 2008
  10. Junio C HamanoSep 15, 2008
  11. Thomas RastSep 15, 2008
  12. Junio C HamanoSep 16, 2008
  13. Jakub NarebskiSep 16, 2008
  14. Andreas EricssonSep 17, 2008
  15. Jakub NarebskiSep 17, 2008
  16. Miklos VajnaSep 17, 2008
  17. Andreas EricssonSep 17, 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.