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

Re: master^ is not a local branch -- huh?!?

From
RGRon Garret <ron1@flownet.com>
Date
Jan 29, 2010, 22:47 UTC
Message-ID
<ron1-0EE62E.14474929012010@news.gmane.org>
In-Reply-To
<op.u7bfjni44oyyg1@alvarezp-ws>
In article <op.u7bfjni44oyyg1@alvarezp-ws>,
 "Octavio Alvarez" <alvarezp@alvarezp.ods.org> wrote:
Show 32 quoted lines
> On Fri, 29 Jan 2010 13:34:01 -0800, Ron Garret <ron1@flownet.com> wrote:
> 
> > In article <op.u7a909hf4oyyg1@alvarezp-ws>,
> >  "Octavio Alvarez" <alvarezp@alvarezp.ods.org> wrote:
> >
> >> On Fri, 29 Jan 2010 12:20:46 -0800, Ron1 <ron1@flownet.com> wrote:
> >>
> >> It means that if you switch to master^ and commit, your commit will
> >> be applied but not tracked (since there is not any branch to advance).
> >>
> >> You would need to do git checkout -b 'new_branch', and then commit.
> >> Now, new_branch will advance with your new commit.
> >
> > OK, I think I understand that.
> >
> > Here's the thing: I can do this:
> >
> > git checkout commit-id filename
> >
> > and restore a particular revision of a particular file to my working
> > tree without affecting my HEAD pointer.  I would expect then that
> >
> > git checkout commit-id
> >
> > with no filename would do the same thing, except restore the entire tree
> > from that commit (including deleting files that didnt' exist then).  And
> > indeed it does that (or at least appears to -- I haven't explored this
> > in depth), except that it DOES move my HEAD pointer to this weird
> > non-branch thing.
> 
> I see. You somehow imply that "git checkout commit-id" overlaps with
> "git reset --hard commit-id".

I'm not intentionally implying that. I don't think git reset --hard does what I want either (but I could be wrong about that).

Show 5 quoted lines
> Even assuming the behavior was not documented in man git-checkout, the
> second example looks useless. What is your use case? What would you do
> after having all the files in the tree switched to another commit,
> without actually updating HEAD to the commit, other than git reset --hard
> again or git revert?
My actual use case is very complicated, but here's a simplified version:

Suppose I'm using git as a back-end for a wiki. I want to look at the state of the entire wiki as it was in some point in the past, and I also want to be able to look at the diffs between individual pages as they were then and as they are now. The most straightforward way I can think of to do that is to simply copy an old commit into my working tree without changing anything else. Then I can look at the old version by simply looking at the files, and I can get the diffs by simply doing a git diff.

If I do a git reset --hard then I get the old version, but I lose my HEAD pointer so that git diff doesn't give me what I want any more.

BTW, it turns out that git checkout [commit] . doesn't do the right thing either. Apparently, it still updates my index, so git diff still doesn't do the right thing.

rg
Previous: Octavio AlvarezNext: Octavio Alvarez
Message 73 of 94 in “master^ is not a local branch -- huh?!?”
  1. Ron1Jan 29, 2010
  2. Jacob HelwigJan 29, 2010
  3. Sverre RabbelierJan 29, 2010
  4. Jacob HelwigJan 29, 2010
  5. Junio C HamanoJan 29, 2010
  6. Sverre RabbelierJan 29, 2010
  7. checkout: warn about 'branch name' rather than 'local branch'Sverre Rabbelier, Jan 29, 2010
  8. checkout: Fix test for s/local branch/branch name/ change.Jacob Helwig, Jan 29, 2010
  9. Sverre RabbelierJan 29, 2010
  10. Nicolas PitreJan 29, 2010
  11. Ron GarretJan 29, 2010
  12. Junio C HamanoJan 29, 2010
  13. Sverre RabbelierJan 29, 2010
  14. Junio C HamanoJan 29, 2010
  15. Nicolas PitreJan 29, 2010
  16. Sverre RabbelierJan 29, 2010
  17. Nicolas PitreJan 29, 2010
  18. Sverre RabbelierJan 29, 2010
  19. Nicolas PitreJan 29, 2010
  20. Junio C HamanoJan 29, 2010
  21. Sverre RabbelierJan 29, 2010
  22. Nicolas PitreJan 29, 2010
  23. Junio C HamanoJan 29, 2010
  24. Jacob HelwigJan 29, 2010
  25. Nicolas PitreJan 29, 2010
  26. Junio C HamanoJan 30, 2010
  27. Sverre RabbelierJan 30, 2010
  28. Junio C HamanoJan 30, 2010
  29. Sverre RabbelierJan 30, 2010
  30. Michael WittenJan 30, 2010
  31. Nicolas PitreJan 30, 2010
  32. Mark LodatoJan 30, 2010
  33. Nicolas PitreJan 30, 2010
  34. Ron GarretJan 30, 2010
  35. Junio C HamanoJan 30, 2010
  36. Ron GarretJan 30, 2010
  37. Nicolas PitreJan 30, 2010
  38. Jay SoffianJan 30, 2010
  39. Junio C HamanoJan 30, 2010
  40. Jay SoffianJan 30, 2010
  41. Nicolas PitreJan 30, 2010
  42. Junio C HamanoJan 30, 2010
  43. Ron GarretJan 30, 2010
  44. Junio C HamanoJan 30, 2010
  45. Jay SoffianJan 30, 2010
  46. Junio C HamanoJan 30, 2010
  47. Ron GarretJan 30, 2010
  48. Mark LodatoJan 30, 2010
  49. Nicolas PitreJan 30, 2010
  50. Mark LodatoJan 30, 2010
  51. Nicolas PitreJan 30, 2010
  52. Nicolas PitreJan 30, 2010
  53. Jay SoffianJan 30, 2010
  54. Nicolas PitreJan 30, 2010
  55. Mark LodatoJan 30, 2010
  56. Junio C HamanoJan 30, 2010
  57. Jeff KingJan 30, 2010
  58. Ron GarretJan 30, 2010
  59. A Large Angry SCMJan 29, 2010
  60. Junio C HamanoJan 29, 2010
  61. Johannes SchindelinJan 30, 2010
  62. Nicolas PitreJan 30, 2010
  63. Johannes SchindelinJan 29, 2010
  64. Ron1Jan 29, 2010
  65. Jacob HelwigJan 29, 2010
  66. Ron GarretJan 29, 2010
  67. Junio C HamanoJan 29, 2010
  68. Ron GarretJan 29, 2010
  69. Junio C HamanoJan 31, 2010
  70. Octavio AlvarezJan 29, 2010
  71. Ron GarretJan 29, 2010
  72. Octavio AlvarezJan 29, 2010
  73. Ron GarretJan 29, 2010
  74. Octavio AlvarezJan 29, 2010
  75. Junio C HamanoJan 29, 2010
  76. Ron GarretJan 29, 2010
  77. Julian PhillipsJan 29, 2010
  78. Ron GarretJan 30, 2010
  79. Ron GarretJan 30, 2010
  80. Junio C HamanoJan 30, 2010
  81. Ron GarretJan 30, 2010
  82. Scott R. GodinJan 29, 2010
  83. Ron GarretJan 29, 2010
  84. Sverre RabbelierJan 29, 2010
  85. Ron GarretJan 29, 2010
  86. Junio C HamanoJan 29, 2010
  87. Ron GarretJan 29, 2010
  88. Michael WittenJan 30, 2010
  89. Junio C HamanoJan 30, 2010
  90. Ron GarretJan 30, 2010
  91. Junio C HamanoJan 30, 2010
  92. Ron GarretJan 30, 2010
  93. Junio C HamanoJan 30, 2010
  94. Ron GarretJan 30, 2010

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.