Git weird behavior when checking HEAD (and options) on Windows

Customization

Imagine a simple repository as follows. You can see that HEAD points to master

 $ git log --decorate --graph * commit 99d20608088ba9c74b57e36a1b0b79ff2be42d68 (HEAD, master) | Author: Saaman < user@domain.com > | Date: Wed Apr 17 16:53:50 2013 +0200 | | My third commit | * commit a4a040c8b5c3923a2ba0f652caae0540f84c4c98 | Author: Saaman < user@domain.com > | Date: Wed Apr 17 16:53:27 2013 +0200 | | My second commit | * commit c5d20f203c11acbb9238ab77581e27a15ccde25e Author: Saaman < user@domain.com > Date: Wed Apr 17 16:52:58 2013 +0200 My first commit $ git reflog 99d2060 HEAD@ {0}: commit: My third commit a4a040c HEAD@ {1}: commit: My second commit c5d20f2 HEAD@ {2}: commit (initial): My first commit 

Law

Now let me do some validation operations

 $ git checkout master Already on 'master' $ git reflog 99d2060 HEAD@ {0}: checkout: moving from master to master 99d2060 HEAD@ {1}: commit: My third commit a4a040c HEAD@ {2}: commit: My second commit c5d20f2 HEAD@ {3}: commit (initial): My first commit $ git checkout HEAD $ git reflog 99d2060 HEAD@ {0}: checkout: moving from master to master 99d2060 HEAD@ {1}: commit: My third commit a4a040c HEAD@ {2}: commit: My second commit c5d20f2 HEAD@ {3}: commit (initial): My first commit 

The reflog shows that

  • HEAD check does not result in a file entry
  • The master check inserts a new entry into the reflog (stating that HEAD moved from master to master )

Try something else

 $ git checkout head Note: checking out 'head'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at 99d2060... My third commit $ git reflog 99d2060 HEAD@ {0}: checkout: moving from master to head 99d2060 HEAD@ {1}: checkout: moving from master to master 99d2060 HEAD@ {2}: commit: My third commit a4a040c HEAD@ {3}: commit: My second commit c5d20f2 HEAD@ {4}: commit (initial): My first commit 

Now in the reflog is displayed

  • HEAD was also allowed SHA 99d2060
  • HEAD now disconnected
  • A new entry has been added to reflog (it is indicated that HEAD moved from master to HEAD )

Questions

I find it difficult to understand this behavior.

  • Why does the HEAD check do nothing in reflog, while the master check (the branch pointing to HEAD ) does?
  • Why does the HEAD check (lowercase) disable HEAD , while git can successfully clear it before the same commit?

Note. These tests were performed on Windows / msysgit

+4
source share
1 answer

After analyzing the code, here are a few parts of the answer:

  • git checkout HEAD does not write anything whether HEAD is disconnected or not.
  • the transition from "master" to "master" is not really useful information, since neither the branch nor its purpose are changed. A bit of useless information to fill out a magazine, but completely harmless.
  • git checkout HEAD does not work on Linux. It only works on Windows because the file system is case insensitive.
+1
source

All Articles