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

Re: [PATCH] checkout -d: explicitly detach HEAD even when switching to the tip of a branch

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Apr 4, 2007, 01:55 UTC
Message-ID
<Pine.LNX.4.64.0704031850240.6730@woody.linux-foundation.org>
In-Reply-To
<7vtzvxt2v3.fsf@assigned-by-dhcp.cox.net>
On Tue, 3 Apr 2007, Junio C Hamano wrote:
> 
> Could anybody remind me why we have the "new != old" check here?
Afaik, it's just so that you can do
	git checkout -f
without having it complain. And I think it just comes from the earlier:
	[ -z "$new" ] && new=$old && new_name="$old_name"

that we did - ie without that it would incorrectly just overwrite the current working tree with the new commit, but not actually do the "git reset" part.

So without that check, the way things used to work (*before* detached heads), if you were to have done

	git checkout <some-random-head>
it would have screwed up the current branch horribly.
With detached heads, I don't think it's needed.
		Linus
Previous: Junio C Hamano
Message 8 of 8 in “checkout -d: explicitly detach HEAD even when switching to the tip of a branch”
  1. checkout -d: explicitly detach HEAD even when switching to the tip of a branchJunio C Hamano, Mar 29, 2007
  2. Xavier MaillardMar 29, 2007
  3. Alex RiesenMar 29, 2007
  4. Xavier MaillardMar 29, 2007
  5. Jakub NarebskiMar 31, 2007
  6. Xavier MaillardMar 31, 2007
  7. Junio C HamanoApr 4, 2007
  8. Linus TorvaldsApr 4, 2007

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.