Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HEAD and head refer to different revisions when in a worktree #1225

Closed
warwickmm opened this issue Jul 3, 2017 · 3 comments

Comments

@warwickmm
Copy link

@warwickmm warwickmm commented Jul 3, 2017

  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options

git version 2.13.0.windows.1
built from commit: eba7af3dbb4c846c6303c5f64102acee696c9ab0
sizeof-long: 4
machine: x86_64
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [Version 6.1.7601]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

I am using the portable installation with default settings.
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

No.

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

Bash

$ bash --version
GNU bash, version 4.4.12(1)-release (x86_64-pc-msys)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

In version 2.13.0, head and HEAD refer to different revisions when in a worktree:

$ git --version
git version 2.13.0.windows.1

$ git init
Initialized empty Git repository in C:/Users/warwickmm/Documents/projects/test/.git/

$ echo "Hello" > hello.txt
$ git add . && git commit -m "Add hello."
[master (root-commit) d10516b] Add hello.
 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt

$ echo "Bye" > bye.txt
$ git add . && git commit -m "Add bye."
[master 80ef77d] Add bye.
 1 file changed, 1 insertion(+)
 create mode 100644 bye.txt

$ git worktree add -b feature/branch ../branch master~
Preparing ../branch (identifier branch)
HEAD is now at d10516b Add hello.

$ cd ../branch

$ git symbolic-ref head
refs/heads/master

$ git symbolic-ref HEAD
refs/heads/feature/branch

If I then open a new shell using version 2.12.2, head and HEAD both refer to the same revisions when in the worktree created above:

$ git --version
git version 2.12.2.windows.2

$ cd /c/Users/warwickmm/Documents/projects/test

$ git symbolic-ref head
refs/heads/feature/branch

$ git symbolic-ref HEAD
refs/heads/feature/branch

This does not appear to be an issue when not in a worktree:

$ git --version
git version 2.13.0.windows.1

$ git init
Initialized empty Git repository in C:/Users/warwickmm/Documents/projects/test/.git/

$ echo "Hello" > hello.txt
$ git add . && git commit -m "Add hello."
[master (root-commit) b280df9] Add hello.
 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt

$ echo "Bye" > bye.txt
$ git add . && git commit -m "Add bye."
[master 454dbf6] Add bye.
 1 file changed, 1 insertion(+)
 create mode 100644 bye.txt

$ git checkout -b feature/branch master~
Switched to a new branch 'feature/branch'

$ git symbolic-ref head
refs/heads/feature/branch

$ git symbolic-ref HEAD
refs/heads/feature/branch
  • What did you expect to occur after running these commands?

I expected that head and HEAD will always point to the same revision (the tip of the current branch).

@warwickmm

This comment has been minimized.

Copy link
Author

@warwickmm warwickmm commented Jul 4, 2017

This issue can also be reproduced in version 2.13.2.windows.1.

@warwickmm

This comment has been minimized.

Copy link
Author

@warwickmm warwickmm commented Jul 12, 2017

It turns out that this is something that affects all case-insensitive filesystems, and isn't specific to this project. See the git mailing list discussion here:

https://public-inbox.org/git/20170711033236.GA11492@lenny.localdomain/

Best practice is to not use head, as there are many other examples where it can lead to undesired behavior.

@warwickmm warwickmm closed this Jul 12, 2017
@kostix

This comment has been minimized.

Copy link

@kostix kostix commented Jul 12, 2017

To make it (maybe more) clear: the current implementation of Git (and GfW, too) uses physical files located in the "Git data directory" (typically it's the ".git" folder located in every non-bare repository) to represent most¹ "refs" — which are tags and branches.

This interacts badly with case-insensitive filesystems


¹ The refs which are not used for some amount of time may eventually transition to the so-called "pack files" due to bookkeeping procedures. In this state, they are no longer represented as regular files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.