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

Re: Re-done kernel archive - real one?

From
Linus Torvalds <torvalds@osdl.org>
Date
Apr 18, 2005, 21:56 UTC
Message-ID
<Pine.LNX.4.58.0504181440020.15725@ppc970.osdl.org>
In-Reply-To
<20050418223359.A16789@flint.arm.linux.org.uk>
On Mon, 18 Apr 2005, Russell King wrote:
> 
> Since this happened, I've been working out what state my tree is in,
> and I restored it back to a state where I had one dangling commit head,
> which was _my_ head.

For the future, if your tree gets messed up to the point where you say "screw it" and just want to go back in time, you can do this (it's equivalent to "undo" in BK speak):

	git log | less -S
	.. find which HEAD it was that you trusted..
In this case your HEAD before I merged with it was this one:
	df4449813c900973841d0fa5a9e9bc7186956e1e
So to get back to that one, you can do
	echo df4449813c900973841d0fa5a9e9bc7186956e1e > .git/HEAD
and now
	cat-file commit $(cat .git/HEAD) | head -1
gives you
	tree a43c4447b2edc9fb01a6369f10c1165de4494c88
so you can restore your checked-out state with
	read-tree a43c4447b2edc9fb01a6369f10c1165de4494c88
	checkout-cache -f -a
	update-cache --refresh
and your tree should be valid again.

Now, to remove any bogus objects, you can then run my "git-prune-script" (look at it carefully first to make sure you realize what you are doing).

NOTE NOTE NOTE! This will _revert_ everything you had done after the "trusted" point. So you may not actually want to do this. Instead:

> It's very much like I somehow committed against the _parent_ of the
> head, rather than the head itself.

That's very common if you just forget to update your new ".git/HEAD" when you do a commit.

Again, it's the tools that make it a bit too easy to mess up. The "commit-tree" thing is supposed to really only be used from scripts (which would do something like

	result=$(commit-tree ...) && echo $result > .git/HEAD

but when doing things by hand, if you forget to update your HEAD, your next commit will be done against the wrong head, and you get dangling commits.

The good news is that this is not that hard to fix up. The _trees_ are all correct, and the objects are all correct, so what you can do is just generate a few new (proper) commit objects, with the right parents. Then you can do the "git-prune-script" thing that will throw away the old broken commits, since they won't be reachable from your new commits (even though their _trees_ will be there and be the same).

So in this case:
	b4a9a5114b3c6da131a832a8e2cd1941161eb348
	+- e7905b2f22eb5d5308c9122b9c06c2d02473dd4f
	   +- dc90c0db0dd5214aca5304fd17ccd741031e5493 <-- extra dangling head
	   +- 488faba31f59c5960aabbb2a5877a0f2923937a3
you can do
	cat-file commit dc90c0db0dd5214aca5304fd17ccd741031e5493

to remind you what your old tree and commit message was, and then just re-commit that tree with the same message but with the proper parent:

	commit-tree xxxx -p 488faba31f59c5960aabbb2a5877a0f2923937a3

and then you need to do the same thing for the other commits (which will now need to be re-based to have the new commit-chain as their parents).

Then, when you fixed up the final one, remember to update .git/HEAD with its commit ID, and now the prune-thing will get rid of the old dangling commits that you just created new duplicates of.

		Linus
Previous: Russell KingNext: Petr Baudis
Message 47 of 60 in “Re-done kernel archive - real one?”
  1. Linus TorvaldsApr 16, 2005
  2. Russell KingApr 17, 2005
  3. Petr BaudisApr 17, 2005
  4. Linus TorvaldsApr 17, 2005
  5. Russell KingApr 17, 2005
  6. Linus TorvaldsApr 17, 2005
  7. Linus TorvaldsApr 17, 2005
  8. Russell KingApr 17, 2005
  9. Linus TorvaldsApr 17, 2005
  10. Russell KingApr 17, 2005
  11. Linus TorvaldsApr 17, 2005
  12. Russell KingApr 17, 2005
  13. Russell KingApr 18, 2005
  14. Petr BaudisApr 18, 2005
  15. Linus TorvaldsApr 18, 2005
  16. Petr BaudisApr 18, 2005
  17. Russell KingApr 17, 2005
  18. Linus TorvaldsApr 17, 2005
  19. David A. WheelerApr 17, 2005
  20. Petr BaudisApr 17, 2005
  21. Russell KingApr 17, 2005
  22. David A. WheelerApr 17, 2005
  23. Martin SchlemmerApr 18, 2005
  24. H. Peter AnvinApr 17, 2005
  25. Jochen RoemlingApr 17, 2005
  26. Randy.DunlapApr 17, 2005
  27. Petr BaudisApr 17, 2005
  28. David WoodhouseApr 17, 2005
  29. Linus TorvaldsApr 17, 2005
  30. Russell KingApr 17, 2005
  31. Russell KingApr 17, 2005
  32. Linus TorvaldsApr 17, 2005
  33. Russell KingApr 18, 2005
  34. Martin SchlemmerApr 18, 2005
  35. Petr BaudisApr 18, 2005
  36. Linus TorvaldsApr 18, 2005
  37. Linus TorvaldsApr 18, 2005
  38. Petr BaudisApr 18, 2005
  39. Russell KingApr 18, 2005
  40. Linus TorvaldsApr 18, 2005
  41. Petr BaudisApr 18, 2005
  42. Russell KingApr 18, 2005
  43. Petr BaudisApr 18, 2005
  44. Russell KingApr 19, 2005
  45. Linus TorvaldsApr 18, 2005
  46. Russell KingApr 18, 2005
  47. Linus TorvaldsApr 18, 2005
  48. Petr BaudisApr 18, 2005
  49. Greg KHApr 18, 2005
  50. Randy.DunlapApr 18, 2005
  51. Linus TorvaldsApr 18, 2005
  52. Greg KHApr 18, 2005
  53. Greg KHApr 18, 2005
  54. Linus TorvaldsApr 18, 2005
  55. Greg KHApr 18, 2005
  56. Linus TorvaldsApr 18, 2005
  57. H. Peter AnvinApr 17, 2005
  58. randy_dunlapApr 17, 2005
  59. David WoodhouseApr 17, 2005
  60. randy_dunlapApr 18, 2005

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.