threads / discuss / 41367

git worktree loses path information after git reset --hard

Subject: git worktree loses path information after git reset --hard

## tl;dr

2 messages between Feb 8, 2016 and Feb 8, 2016.

replies: 1people: 2as markdown or json

Daniel Egger· Feb 8, 2016, 08:07 UTC · lore
Hi guys,
I stumbled across a problem with worktrees recently; I incorrectly opened a ticket a GitHub for that and it was suggested that it might be fixed in 2.7.1 so I held off reporting it here but as it turned out it is still broken in 2.7.1 so here we go.
The problem is that the paths of the worktrees in $GIT_DIR/worktrees/worktree_name/gitdir are rewritten to read .git instead of /path/to/worktree/root/.git after a git reset --hard (and potentially other operations) which causes all worktrees in git worktree list to point to the current worktree instead of the main repository path.
Let me demonstrate:

# git worktree list /Users/user/Desktop/Source/Product 2991e32 [master] /Users/user/Desktop/Source/Product-2.1 3fc1082 [releases/master-2.1] /Users/user/Desktop/Source/Product-2.2 3ccc3fe [releases/master-2.2] /Users/user/Desktop/Source/Product-2.3 4044881 [releases/master-2.3] # cd /Users/user/Desktop/Source/Product-2.1 # git reset --hard # cd /Users/user/Desktop/Source/Product-2.2 # git reset --hard # cd /Users/user/Desktop/Source/Product # git worktree list /Users/user/Desktop/Source/Product 2991e32 [master] /Users/user/Desktop/Source/Product 3fc1082 [releases/master-2.1] /Users/user/Desktop/Source/Product 3ccc3fe [releases/master-2.2] /Users/user/Desktop/Source/Product-2.3 4044881 [releases/master-2.3]

Servus,
      Daniel
Junio C Hamano· Feb 8, 2016, 19:49 UTC · re: Daniel Egger · lore

Re: git worktree loses path information after git reset --hard

Daniel Egger <daniel@eggers-club.de> writes:
> I stumbled across a problem with worktrees recently; I incorrectly
> opened a ticket a GitHub for that and it was suggested that it
> might be fixed in 2.7.1 so I held off reporting it here but as it
> turned out it is still broken in 2.7.1 so here we go.

Instead of holding off, report them early after checking the list archive to see if it is already resolved. You may be asked to verify the proposed fix works for you with this and that patch, and you can help us that way, too, in addition to your helping us by throwing us a bug report.

I think the fix for this particular one is cooking in 'next' and about to graduate to 'master' (hence hopefully it can be part of 2.7.2).

Thanks.

← back to recent threads