{"thread":{"id":"44079","subject":"Left with empty files after \"git stash pop\" when system hung","startedAt":"2016-09-13T21:46:09Z","lastAt":"2016-09-14T22:58:50Z","messageCount":2,"participants":["Daniel Hahler","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"301871","messageId":"5b203a8e-faa8-9f6e-8cdd-1024194e74a3@thequod.de","threadId":"44079","inReplyTo":null,"subject":"Left with empty files after \"git stash pop\" when system hung","fromName":"Daniel Hahler","fromEmail":"genml+git-2016@thequod.de","sentAt":"2016-09-13T21:39:56Z","receivedAt":"2016-09-13T21:46:09Z","isPatch":false,"sender":{"key":"genml+git-2016@thequod.de","avatar":null},"body":"I have used \"git stash --include-untracked\", checked out another branch,\nwent back, and \"git stash pop\"ed the changes.\nThen my system crashed/hung (music that was playing was repeated in a\nloop).  I have waited for some minutes, and then turned it off.\n\nAfterwards, the repository in question was in a state where all files\ncontained in the stash were empty.\n\"git status\" looked good on first sight: all the untracked and modified\nfiles were listed there; but they were empty.\n\n  % git fsck --lost-found\n  error: object file .git/objects/04/1e659b5dbfd3f0be351a782b54743692875aec is empty\n  error: object file .git/objects/04/1e659b5dbfd3f0be351a782b54743692875aec is empty\n  fatal: loose object 041e659b5dbfd3f0be351a782b54743692875aec (stored in .git/objects/04/1e659b5dbfd3f0be351a782b54743692875aec) is corrupt\n  % find .git/objects -size 0|wc -l\n  12\n\nI would have assumed that the \"stash pop\" operation would be \"atomic\",\ni.e. it should not remove the stash object before other objects have\nbeen written successfully.\n\nThe filesystem in question is ext4, and I am using Arch Linux.\n\nI have removed all empty files in .git/objects and tried to find the\nprevious stash with `gitk --all $( git fsck | awk '{print $3}' )` then,\nbut it appears to have disappeared.\n\nPlease CC me in replies.\n\n\nCheers,\nDaniel.\n\n-- \nhttp://daniel.hahler.de/\n\n"},{"id":"301939","messageId":"20160914225828.hlsc2ae4vfghmqv7@sigill.intra.peff.net","threadId":"44079","inReplyTo":"5b203a8e-faa8-9f6e-8cdd-1024194e74a3@thequod.de","subject":"Re: Left with empty files after \"git stash pop\" when system hung","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-09-14T22:58:30Z","receivedAt":"2016-09-14T22:58:50Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Sep 13, 2016 at 11:39:56PM +0200, Daniel Hahler wrote:\n\n> I have used \"git stash --include-untracked\", checked out another branch,\n> went back, and \"git stash pop\"ed the changes.\n> Then my system crashed/hung (music that was playing was repeated in a\n> loop).  I have waited for some minutes, and then turned it off.\n> \n> Afterwards, the repository in question was in a state where all files\n> contained in the stash were empty.\n> \"git status\" looked good on first sight: all the untracked and modified\n> files were listed there; but they were empty.\n> \n>   % git fsck --lost-found\n>   error: object file .git/objects/04/1e659b5dbfd3f0be351a782b54743692875aec is empty\n>   error: object file .git/objects/04/1e659b5dbfd3f0be351a782b54743692875aec is empty\n>   fatal: loose object 041e659b5dbfd3f0be351a782b54743692875aec (stored in .git/objects/04/1e659b5dbfd3f0be351a782b54743692875aec) is corrupt\n>   % find .git/objects -size 0|wc -l\n>   12\n>\n> [...]\n> The filesystem in question is ext4, and I am using Arch Linux.\n\nIs your filesystem mounted with data=writeback? Git should never write\nan empty object file; it writes the content to a temporary file, and\nthen hardlinks it into place. If your filesystem does not order data and\nmetadata writes (i.e., the hardlink may get journaled and picked\nup, even though the data did not hit the disk), then you can end up with\nempty files. If you set core.fsyncobjectfiles in your config file, then\nGit will fsync each object write (at the cost of some performance).\n\n> I would have assumed that the \"stash pop\" operation would be \"atomic\",\n> i.e. it should not remove the stash object before other objects have\n> been written successfully.\n\nStash does not remove any objects at all; it should only be updating the\nstash reflog to delete the entry (which also happens via write to a\ntempfile and rename, though I don't think we ever fsync it, even with\ncore.fsyncobjectfiles).\n\nThe empty object you found is probably the result of a write too close\nto the crash. In general I wouldn't expect \"stash pop\" to write, but I\nsuspect it may in order to populate the index.\n\n> I have removed all empty files in .git/objects and tried to find the\n> previous stash with `gitk --all $( git fsck | awk '{print $3}' )` then,\n> but it appears to have disappeared.\n\nfsck won't mention the object as dangling if it's reachable from a\nreflog. Did you try \"git stash list\" (or just \"git log -g refs/stash\")?\n\n-Peff\n"}]}