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

Re: user manual question

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Dec 29, 2008, 19:30 UTC
Message-ID
<alpine.LNX.1.00.0812291358460.19665@iabervon.org>
In-Reply-To
<gjauel$94s$4@ger.gmane.org>
On Mon, 29 Dec 2008, Zorba wrote:
> so a detached HEAD is just a HEAD that is not sitting on a tip ?

If you used CVS (extensively) back in the day, a detached HEAD is like what you get if you do something like "cvs checkout -D yesterday" (CVS called it "sticky tags"); you have a working directory that contains some revision that isn't your latest revision. If you make changes, they can't go into the history in the normal fashion, but you can build the project and figure out how it worked back then.

With git, of course, you can do things you couldn't do from that state with CVS. Because git supports forking history, you can make commits and create a new branch to be on. Because git can handle having visibility into other people's branches, you can get a detached HEAD by checking out somebody else's branch (something like origin/next, for example).

The normal "attached HEAD" state is that there's some branch that you update when you make a commit; the "detached HEAD" state means that, when you make a commit, no branch is affected.

Show 5 quoted lines
> i.e. if I do $ git reset --hard HEAD^
> 
> ...pointing HEAD to the previous committ
> 
> this is a detached HEAD

Nope, it's "git checkout (something that isn't one of your branches)", just like CVS.

Git is like knitting. Commits are loops of yarn that hold other loops (their parents) in place; branches are knitting needles that keep new loops from falling out before other loops are holding them, and which hold different loops at different times as you work; HEAD is the tip of a needle that you use to make new loops. You usually use the tip of one of your regular needles to make new loops, and then the body of the needle holds the loop, but you could also use your fingers or something that will just make the loop temporarily; that's a detached HEAD, because it doesn't have the body of a needle behind it to hold loops when you use it for something else.

	-Daniel
*This .sig left intentionally blank*
Previous: Sitaram Chamarty
Message 12 of 12 in “user manual question”
  1. ZorbaDec 28, 2008
  2. Sitaram ChamartyDec 28, 2008
  3. Dilip MDec 28, 2008
  4. ZorbaDec 29, 2008
  5. ZorbaDec 28, 2008
  6. Sitaram ChamartyDec 29, 2008
  7. Dilip MDec 29, 2008
  8. ZorbaDec 29, 2008
  9. Björn SteinbrinkDec 29, 2008
  10. Markus HeidelbergDec 29, 2008
  11. Sitaram ChamartyDec 29, 2008
  12. Daniel BarkalowDec 29, 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.