{"thread":{"id":"37126","subject":"[BUG] checkout --orphan breaks HEAD reflog","startedAt":"2014-07-14T19:44:25Z","lastAt":"2014-07-14T19:44:25Z","messageCount":1,"participants":["Aleksander Nitecki"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"246006","messageId":"53C43319.7000208@itogi.re","threadId":"37126","inReplyTo":null,"subject":"[BUG] checkout --orphan breaks HEAD reflog","fromName":"Aleksander Nitecki","fromEmail":"ixendr@itogi.re","sentAt":"2014-07-14T19:44:25Z","receivedAt":"2014-07-14T19:44:25Z","isPatch":false,"sender":{"key":"ixendr@itogi.re","avatar":null},"body":"Hi, this is my first mail to this list (and I'm not a native English speaker), so let me apologise from the start for any slips in following message.\n\nOk, so I think I've found a bug in git.\nIt concerns orphan checkouts breaking (gapping in non-traversable way) the HEAD reflog display.\n\n% git --version\ngit version 2.0.1\n\n\n# Repro commands; output omitted.\n\n% mkdir /tmp/git-orphan-checkout-reflog-bug\n% cd /tmp/git-orphan-checkout-reflog-bug\n% git init\n% echo a  > foo; git add foo; git commit -m 'newly created master; rev. a'\n% echo b >> foo; git add foo; git commit -m 'master; rev. b'\n% echo c >> foo; git add foo; git commit -m 'master; rev. c'\n% git checkout --orphan some_orphan_branch\n% echo 1  > bar; git add bar; git commit -m 'newly created orphan branch; rev. 1'\n% echo 2 >> bar; git add bar; git commit -m 'orphan branch; rev. 2'\n% echo 3 >> bar; git add bar; git commit -m 'orphan branch; rev. 3'\n\n\n# Actual (IMHO buggy) output\n\n% git reflog HEAD\n1af4e3c HEAD@{0}: commit: orphan branch; rev. 3\n6d200b4 HEAD@{1}: commit: orphan branch; rev. 2\ned4ad67 HEAD@{2}: commit (initial): newly created orphan branch; rev. 1\n\n% git reflog HEAD@{3}\nwarning: Log .git/logs/HEAD has gap after Mon, 14 Jul 2014 20:55:05 +0200.\n0cada62 HEAD@{3}: commit: master; rev. c\n42d7cc3 HEAD@{4}: commit: master; rev. b\n222a0b3 HEAD@{5}: commit (initial): newly created master; rev. a\n\n\n# Expected output:\n\n% git reflog HEAD\n1af4e3c HEAD@{0}: commit: orphan branch; rev. 3\n6d200b4 HEAD@{1}: commit: orphan branch; rev. 2\ned4ad67 HEAD@{2}: commit (initial): newly created orphan branch; rev. 1\nwarning: Log .git/logs/HEAD has gap after Mon, 14 Jul 2014 20:55:05 +0200.\n0cada62 HEAD@{3}: commit: master; rev. c\n42d7cc3 HEAD@{4}: commit: master; rev. b\n222a0b3 HEAD@{5}: commit (initial): newly created master; rev. a\n\nWell, actually git doesn't seem to show warning messages when traversing reflogs with other gaps, but only when started from point where a gap is.\nWhether those warnings should be displayed while traversing the reflog, not only when starting from gapped entries is another matter, but I think it could be useful.\n\n\n# Raw reflog file (shortened to fit in 80 columns).\n# Omissions marked with ##. Full contents in attachment.\n# (does sending attachments to mailing list even work? Sorry, if it doesn't.)\n\n% cat .git/logs/HEAD\n00000## 222a0## ## commit (initial): newly created master; rev. a\n222a0## 42d7c## ## commit: master; rev. b\n42d7c## 0cada## ## commit: master; rev. c\n00000## ed4ad## ## commit (initial): newly created orphan branch; rev. 1\ned4ad## 6d200## ## commit: orphan branch; rev. 2\n6d200## 1af4e## ## commit: orphan branch; rev. 3\n\nSo the problem seems to be that git stops traversing the reflog after finding first initial commit (all-0s hash) and completely ignores rest of log.\nThe problem is that this commit is initial only to the orphaned branch, not to the whole repo.\n\n\n\n0000000000000000000000000000000000000000 222a0b38654d2c8cf3026db5913d21857a5a17e7 Aleksander Nitecki <ixendr@itogi.re> 1405364070 +0200 commit (initial): newly created master; rev. a\n222a0b38654d2c8cf3026db5913d21857a5a17e7 42d7cc39cb4e89e02e8b0868d4bd32d18c0fcd84 Aleksander Nitecki <ixendr@itogi.re> 1405364086 +0200 commit: master; rev. b\n42d7cc39cb4e89e02e8b0868d4bd32d18c0fcd84 0cada62df007aa9ec1ee00816adb1b1d9ce3f593 Aleksander Nitecki <ixendr@itogi.re> 1405364105 +0200 commit: master; rev. c\n0000000000000000000000000000000000000000 ed4ad679d3c6903b3bbad477f8e61a85afa882a5 Aleksander Nitecki <ixendr@itogi.re> 1405364324 +0200 commit (initial): newly created orphan branch; rev. 1\ned4ad679d3c6903b3bbad477f8e61a85afa882a5 6d200b41f230762585e0c25b9b33336e0cf69ba9 Aleksander Nitecki <ixendr@itogi.re> 1405364371 +0200 commit: orphan branch; rev. 2\n6d200b41f230762585e0c25b9b33336e0cf69ba9 1af4e3cf1576d05fa5c579c8090e2961ebafd4e9 Aleksander Nitecki <ixendr@itogi.re> 1405364421 +0200 commit: orphan branch; rev. 3\n"}]}