{"thread":{"id":"40484","subject":"git rev-list --all --reflog does not include worktree references","startedAt":"2015-10-05T19:08:19Z","lastAt":"2015-10-06T09:39:09Z","messageCount":2,"participants":["Andreas Schwab","Michael J Gruber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"271151","messageId":"87io6l16cc.fsf@igel.home","threadId":"40484","inReplyTo":null,"subject":"git rev-list --all --reflog does not include worktree references","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2015-10-05T19:08:19Z","receivedAt":"2015-10-05T19:08:19Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"When running git rev-list --all --reflog in the main worktree it doesn't\ninclude commits only referenced by the worktrees, neither HEAD nor its\nreflog.\n\n$ git init test\n$ cd test\n# add some commits\n$ touch 1; git add 1; git commit -m 1\n$ touch 2; git add 2; git commit -m 2\n# add new worktree\n$ git worktree add ../test2 master^{}\n$ cd ../test2\n# add more commits\n$ touch 3; git add 3; git commit -m 3\n$ touch 4; git add 4; git commit -m 4\n# create an unreferenced commit\n$ git checkout @^\n# both commands should give the same number of commits\n$ git rev-list --reflog | wc -l\n4\n$ git -C ../test rev-list --all --reflog | wc -l\n2\n\nIIUC this will cause git gc to prune references from worktrees too\nearly.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"271209","messageId":"561396BD.9030205@drmicha.warpmail.net","threadId":"40484","inReplyTo":"87io6l16cc.fsf@igel.home","subject":"Re: git rev-list --all --reflog does not include worktree references","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-10-06T09:39:09Z","receivedAt":"2015-10-06T09:39:09Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Andreas Schwab venit, vidit, dixit 05.10.2015 21:08:\n> When running git rev-list --all --reflog in the main worktree it doesn't\n> include commits only referenced by the worktrees, neither HEAD nor its\n> reflog.\n\nHEAD is per worktree, so other worktrees' HEADs should not be included\nin \"--all\", I would think.\n\n> $ git init test\n> $ cd test\n> # add some commits\n> $ touch 1; git add 1; git commit -m 1\n> $ touch 2; git add 2; git commit -m 2\n> # add new worktree\n> $ git worktree add ../test2 master^{}\n> $ cd ../test2\n> # add more commits\n> $ touch 3; git add 3; git commit -m 3\n> $ touch 4; git add 4; git commit -m 4\n> # create an unreferenced commit\n> $ git checkout @^\n> # both commands should give the same number of commits\n> $ git rev-list --reflog | wc -l\n> 4\n> $ git -C ../test rev-list --all --reflog | wc -l\n> 2\n> \n> IIUC this will cause git gc to prune references from worktrees too\n> early.\n\nSince HEAD is per worktree, its reflog is so, too. So I think that \"git\nrev-list\" is actually right.\n\nWhat's worrysome is that running \"git prune -n\" gives different results,\ndepending on whether you run it in the main worktree or the new worktree.\n\nIn fact, running \"git prune\" in the main worktree followed by \"git\nreflog\" in the new worktree results in\n\nfatal: bad object HEAD\n\nSo, \"rev-list\" should learn something like \"--reflogs\" or (better)\n\"--worktrees\" to make it look at worktree specific refs, too, and prune\nshould use that, of course. \"prune\" does know about worktrees, but I\nguess it looks at HEADs only, not their reflogs.\n\nMichael\n"}]}