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

Re: [PATCH] detached HEAD -- finishing touches

From
Theodore Tso <tytso@mit.edu>
Date
Feb 1, 2007, 21:52 UTC
Message-ID
<20070201215242.GA1775@thunk.org>
In-Reply-To
<7vlkjip7mu.fsf_-_@assigned-by-dhcp.cox.net>
On Thu, Feb 01, 2007 at 01:08:41AM -0800, Junio C Hamano wrote:
Show 7 quoted lines
>     [git.git]$ git checkout master
>     You are not on any branch and switching to branch 'master'
>     may lose your changes.  At this point, you can do one of two things:
>      (1) Decide it is Ok and say 'git checkout -f master';
>      (2) Start a new branch from the current commit, by saying
>          'git checkout -b <branch-name>'.
>     Leaving your HEAD detached; not switching to branch 'master'.

How hard would it be to simply simply set a flag once git has entered a detached HEAD state, and clear the flag if any git operation has modified the repository at all. If the flag is still set, then obviously the repository hasn't changed and so there are no changes that could be lost. i.e., if I've do:

<tytso@candygram> {/usr/projects/e2fsprogs/hg-to-git/test}  [master]
181% git checkout 2ab15cafae661765ecd7f256b1993b94d5534faf
warning: you are not on ANY branch anymore.
If you meant to create a new branch from this checkout, you may still do
so (now or later) by using -b with the checkout command again.  Example:
  git checkout -b <new_branch_name>
<tytso@candygram> {/usr/projects/e2fsprogs/hg-to-git/test}  
182% git checkout master
You are not on any branch and switching to branch 'master'
may lose your changes.  At this point, you can do one of two things:
 (1) Decide it is Ok and say 'git checkout -f master';
 (2) Start a new branch from the current commit, by saying
     'git checkout -b <branch-name>'.
Leaving your HEAD detached; not switching to branch 'master'.

It's really obvious there are no changes, so it makes git seem a little stupid to always be saying "may lose your changes". Can we simply let git know that there weren't any changes?

Otherwise we're just training users to just always use the -f option.
						- Ted
Previous: Jakub NarebskiNext: Junio C Hamano
Message 29 of 35 in “tone down the detached head warning”
  1. tone down the detached head warningNicolas Pitre, Jan 31, 2007
  2. Jeff KingJan 31, 2007
  3. Jakub NarebskiJan 31, 2007
  4. Jeff KingJan 31, 2007
  5. Jakub NarebskiJan 31, 2007
  6. Carl WorthJan 31, 2007
  7. Jakub NarebskiFeb 1, 2007
  8. Andy ParkinsFeb 1, 2007
  9. Matthias LederhoferFeb 1, 2007
  10. Nicolas PitreFeb 1, 2007
  11. Jeff KingFeb 1, 2007
  12. Junio C HamanoFeb 1, 2007
  13. Jeff KingFeb 1, 2007
  14. Nicolas PitreFeb 1, 2007
  15. Jeff KingFeb 1, 2007
  16. detached HEAD -- finishing touchesJunio C Hamano, Feb 1, 2007
  17. Raimund BauerFeb 1, 2007
  18. Alex RiesenFeb 1, 2007
  19. Alex RiesenFeb 1, 2007
  20. git-checkout: disable guides how to switch branches with ui.guideMatthias Lederhofer, Feb 1, 2007
  21. Junio C HamanoFeb 1, 2007
  22. Matthias LederhoferFeb 1, 2007
  23. Junio C HamanoFeb 1, 2007
  24. Matthias LederhoferFeb 1, 2007
  25. Carl WorthFeb 1, 2007
  26. Nicolas PitreFeb 1, 2007
  27. Carl WorthFeb 1, 2007
  28. Jakub NarebskiFeb 1, 2007
  29. Theodore TsoFeb 1, 2007
  30. Junio C HamanoFeb 2, 2007
  31. Theodore TsoFeb 2, 2007
  32. Carl WorthFeb 2, 2007
  33. Junio C HamanoFeb 2, 2007
  34. Carl WorthFeb 2, 2007
  35. Junio C HamanoFeb 2, 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.