Re: Bug with git worktrees and git init
- From
Michael J Gruber <git@drmicha.warpmail.net>
- Date
- Aug 23, 2016, 15:21 UTC
- Message-ID
- <f55e70fa-5244-66a0-d3a7-c6479528039d@drmicha.warpmail.net>
- In-Reply-To
- <CALqjkKZO_y0DNcRJjooyZ7Eso7yBMGhvZ6fE92oO4Su7JeCeng@mail.gmail.com>
Max Nordlund venit, vidit, dixit 23.08.2016 14:35:
Show 25 quoted lines
> Hi, > > I've been using multiple worktrees for months without issue (it's a > great feature, thanks), until recently when I wanted to add hooks to > them. So, when I added a template for the hooks, everything was fine > until I did a git reset --hard in the original repo which both applied > those changes to the other worktrees' working tree (the files on > disk), and made my master branch kinda lose it's connection to the > remote/think it was a kinda bare repo. > > To reproduce this: > > ``` > mkdir source-repo > cd source-repo > git init > touch foo > git add foo > git commit -m 'Add foo' > git worktree add ../worktree # which also creates a new branch 'worktree' > touch bar > git add bar > git commit -m 'Add bar' > cd ../worktree > git init
This is where the problem is created already: git init does not quite notice that it is in a linked worktree. It treats
source-repo/.git/worktrees/worktree
as a proper gitdir and creates the full gitdir structure in there (branches, hooks, info) which is usually shared among worktrees; also, it adds the config setting
core.worktree = <abspath>/worktree
to the main config (source-repo/.git/config) which is why "git status" thinks that bar is missing - it indeed is in that worktree.
I've cc'ed the master of worktrees.
Show 15 quoted lines
> cd ../source-repo > git reset --hard master > cd ../worktree > git status # Suddenly `bar` has appear the working tree and is not tracked > ``` > > I don't really now what is up with this, but I did notice that it is > the last worktree in which git init has been run that is affected. I > only ran git init to copy the hooks from the template, but if that is > not something you should do in a worktree then a check would have been > nice. > > Thanks for this awesome tool, and I hope this helps > Max Nordlund >