{"thread":{"id":"41174","subject":"Can't diff against the 00000000 revision","startedAt":"2016-01-12T15:17:24Z","lastAt":"2016-01-12T18:52:41Z","messageCount":8,"participants":["Stefan Monnier","Jeff King","Andreas Schwab","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"275807","messageId":"jwv4meiygrc.fsf-monnier+gmane.comp.version-control.git@gnu.org","threadId":"41174","inReplyTo":null,"subject":"Can't diff against the 00000000 revision","fromName":"Stefan Monnier","fromEmail":"monnier@iro.umontreal.ca","sentAt":"2016-01-12T15:17:24Z","receivedAt":"2016-01-12T15:17:24Z","isPatch":false,"sender":{"key":"monnier@iro.umontreal.ca","avatar":null},"body":"If I look at the initial commit on a branch, I see something like:\n\n    % git show d59cfff346c3e210adc26501f8cebf8da5ab2e7d\n    commit d59cfff346c3e210adc26501f8cebf8da5ab2e7d\n    Author: Stefan Monnier <monnier@iro.umontreal.ca>\n    Date:   Wed Dec 2 20:46:51 2015 -0500\n    \n        Initial release\n    \n    diff --git a/bugit b/bugit\n    new file mode 100755\n    index 0000000..681bd38\n    --- /dev/null\n    +++ b/bugit\n    @@ -0,0 +1,512 @@\n    ...\n\nwhich is great.  But I can't get the same result with\n\n    git diff 0000000..681bd38\n\nbecause it complains:\n\n    % git diff 0000000..681bd38\n    fatal: ambiguous argument '0000000..681bd38': unknown revision or path not in the working tree.\n    Use '--' to separate paths from revisions, like this:\n    'git <command> [<revision>...] -- [<file>...]'\n    %\n\nI bumped into this problem in a post-receive hook where I need to pay\nattention to all newly added files, and where this problem means that\nI can't use the same code for a newly added branch as for a push on\na pre-existing branch.\n\nI currently work around the problem by adding a dummy empty branch, but\nbeing able to use the revision 00000000 as a known reference to an empty\ntree would come in really handy, and since it's already used at various\nplaces in Git (post-receive hook and \"git show\" output, at least), it\nwould seem like a natural extension.\n\n\n        Stefan\n"},{"id":"275812","messageId":"20160112153239.GA8041@sigill.intra.peff.net","threadId":"41174","inReplyTo":"jwv4meiygrc.fsf-monnier+gmane.comp.version-control.git@gnu.org","subject":"Re: Can't diff against the 00000000 revision","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-01-12T15:32:39Z","receivedAt":"2016-01-12T15:32:39Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jan 12, 2016 at 10:17:24AM -0500, Stefan Monnier wrote:\n\n> If I look at the initial commit on a branch, I see something like:\n> \n>     % git show d59cfff346c3e210adc26501f8cebf8da5ab2e7d\n>     commit d59cfff346c3e210adc26501f8cebf8da5ab2e7d\n>     Author: Stefan Monnier <monnier@iro.umontreal.ca>\n>     Date:   Wed Dec 2 20:46:51 2015 -0500\n>     \n>         Initial release\n>     \n>     diff --git a/bugit b/bugit\n>     new file mode 100755\n>     index 0000000..681bd38\n>     --- /dev/null\n>     +++ b/bugit\n>     @@ -0,0 +1,512 @@\n>     ...\n> \n> which is great.  But I can't get the same result with\n> \n>     git diff 0000000..681bd38\n> \n> because it complains:\n> \n>     % git diff 0000000..681bd38\n>     fatal: ambiguous argument '0000000..681bd38': unknown revision or path not in the working tree.\n>     Use '--' to separate paths from revisions, like this:\n>     'git <command> [<revision>...] -- [<file>...]'\n>     %\n\nRight. There is no \"000000\" blob; it's just a syntactic placeholder.\n\nIf you want to diff against the empty blob, you can. Its name is:\n\n  $ git hash-object -t blob /dev/null\n  e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n\n> I bumped into this problem in a post-receive hook where I need to pay\n> attention to all newly added files, and where this problem means that\n> I can't use the same code for a newly added branch as for a push on\n> a pre-existing branch.\n\nKeep in mind that the \"000000\" in your example is showing the change in\nthe _blob_, not the change in revisions. Even if it were not 0's, you\ncould not run \"git diff A..B\" on it, because that syntax only works with\ncommits.\n\nSo the corner case you need to deal with is not about a newly added\nbranch; it is about a newly added file (or in the opposite direction, a\ndeleted file).\n\nOr from your description, maybe you are also running into the all-zero\nsha1 in the argument to the post-receive hook (where it is standing in\nfor a commit sha1 on a newly-pushed branch).\n\n> I currently work around the problem by adding a dummy empty branch, but\n> being able to use the revision 00000000 as a known reference to an empty\n> tree would come in really handy, and since it's already used at various\n> places in Git (post-receive hook and \"git show\" output, at least), it\n> would seem like a natural extension.\n\nThe empty tree also has a name:\n\n  $ git hash-object -t tree /dev/null\n  4b825dc642cb6eb9a060e54bf8d69288fbee4904\n\nand you can diff against that.\n\nAnd hopefully that explains why \"000000\" does not necessarily make a\ngood placeholder for \"the empty thing\". There are multiple empty things,\nand it is not clear what:\n\n  git diff 0000000 1234abcd\n\nmeans. Is 0000000 a tree? A blob?\n\n-Peff\n"},{"id":"275813","messageId":"20160112153757.GB8041@sigill.intra.peff.net","threadId":"41174","inReplyTo":"20160112153239.GA8041@sigill.intra.peff.net","subject":"Re: Can't diff against the 00000000 revision","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-01-12T15:37:58Z","receivedAt":"2016-01-12T15:37:58Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jan 12, 2016 at 10:32:39AM -0500, Jeff King wrote:\n\n> > I currently work around the problem by adding a dummy empty branch, but\n> > being able to use the revision 00000000 as a known reference to an empty\n> > tree would come in really handy, and since it's already used at various\n> > places in Git (post-receive hook and \"git show\" output, at least), it\n> > would seem like a natural extension.\n> \n> The empty tree also has a name:\n> \n>   $ git hash-object -t tree /dev/null\n>   4b825dc642cb6eb9a060e54bf8d69288fbee4904\n\nBy the way, the empty tree and empty blob objects are baked-in to git,\nso you can always rely on diffing against them. IOW, it is fine to\nwrite:\n\n  while read old new ref; do\n\tif test \"$old\" = \"0000000000000000000000000000000000000000\"; then\n\t\told=4b825dc642cb6eb9a060e54bf8d69288fbee4904\n\tfi\n\tgit diff-tree $old $new | whatever_checks_you_want_to_do\n  done\n\nin your post-receive hook.\n\n-Peff\n"},{"id":"275816","messageId":"jwvr3hmwz1n.fsf-monnier+gmane.comp.version-control.git@gnu.org","threadId":"41174","inReplyTo":"20160112153239.GA8041@sigill.intra.peff.net","subject":"Re: Can't diff against the 00000000 revision","fromName":"Stefan Monnier","fromEmail":"monnier@iro.umontreal.ca","sentAt":"2016-01-12T16:26:24Z","receivedAt":"2016-01-12T16:26:24Z","isPatch":false,"sender":{"key":"monnier@iro.umontreal.ca","avatar":null},"body":">> I currently work around the problem by adding a dummy empty branch, but\n>> being able to use the revision 00000000 as a known reference to an empty\n>> tree would come in really handy, and since it's already used at various\n>> places in Git (post-receive hook and \"git show\" output, at least), it\n>> would seem like a natural extension.\n\n> The empty tree also has a name:\n>\n>   $ git hash-object -t tree /dev/null\n>   4b825dc642cb6eb9a060e54bf8d69288fbee4904\n\nYay!\n\n   git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904..d59cfff346c3e210adc26501f8cebf8da5ab2e7d\n\nseems to give me the expected diff.\nThanks!\n\n> And hopefully that explains why \"000000\" does not necessarily make a\n> good placeholder for \"the empty thing\". There are multiple empty things,\n> and it is not clear what:\n\n>   git diff 0000000 1234abcd\n\n> means. Is 0000000 a tree? A blob?\n\nWell, Git is the one who uses 000000 to refer to an empty thing, but\nindeed it seems like it does inconsistently: it's sometimes used as the\n\"empty blob\" and sometimes as an \"empty tree\".\n\n\n        Stefan\n"},{"id":"275819","messageId":"87io2yekhp.fsf@igel.home","threadId":"41174","inReplyTo":"20160112153239.GA8041@sigill.intra.peff.net","subject":"Re: Can't diff against the 00000000 revision","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2016-01-12T18:11:14Z","receivedAt":"2016-01-12T18:11:14Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> And hopefully that explains why \"000000\" does not necessarily make a\n> good placeholder for \"the empty thing\". There are multiple empty things,\n> and it is not clear what:\n>\n>   git diff 0000000 1234abcd\n>\n> means. Is 0000000 a tree? A blob?\n\nPerhaps there should be an easy syntax for an empty thing, something\nlike 0^{tree} and 0^{blob}.  Not sure whether it is worth the effort,\nthough.\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":"275821","messageId":"20160112182002.GA9244@sigill.intra.peff.net","threadId":"41174","inReplyTo":"jwvr3hmwz1n.fsf-monnier+gmane.comp.version-control.git@gnu.org","subject":"Re: Can't diff against the 00000000 revision","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-01-12T18:20:03Z","receivedAt":"2016-01-12T18:20:03Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jan 12, 2016 at 11:26:24AM -0500, Stefan Monnier wrote:\n\n> > And hopefully that explains why \"000000\" does not necessarily make a\n> > good placeholder for \"the empty thing\". There are multiple empty things,\n> > and it is not clear what:\n> \n> >   git diff 0000000 1234abcd\n> \n> > means. Is 0000000 a tree? A blob?\n> \n> Well, Git is the one who uses 000000 to refer to an empty thing, but\n> indeed it seems like it does inconsistently: it's sometimes used as the\n> \"empty blob\" and sometimes as an \"empty tree\".\n\nYes. You can think of it kind of like a NULL pointer; it just means\n\"nothing\". So its meaning is context-dependent. The problem is if we\nexpect to feed it back to git in a place where the context isn't\nobvious.\n\n-Peff\n"},{"id":"275822","messageId":"20160112182115.GB9244@sigill.intra.peff.net","threadId":"41174","inReplyTo":"87io2yekhp.fsf@igel.home","subject":"Re: Can't diff against the 00000000 revision","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-01-12T18:21:16Z","receivedAt":"2016-01-12T18:21:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jan 12, 2016 at 07:11:14PM +0100, Andreas Schwab wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > And hopefully that explains why \"000000\" does not necessarily make a\n> > good placeholder for \"the empty thing\". There are multiple empty things,\n> > and it is not clear what:\n> >\n> >   git diff 0000000 1234abcd\n> >\n> > means. Is 0000000 a tree? A blob?\n> \n> Perhaps there should be an easy syntax for an empty thing, something\n> like 0^{tree} and 0^{blob}.  Not sure whether it is worth the effort,\n> though.\n\nI think I proposed a magic EMPTY_TREE token or something like that at\none point. It is slightly more convenient than trying to remember the\nexact tree sha1, but I think in practice it doesn't save much effort\n(outside of scripts, you can often use \"--root\" to accomplish the same\nthing, depending on the command being run).\n\n-Peff\n"},{"id":"275827","messageId":"xmqqpox6tyti.fsf@gitster.mtv.corp.google.com","threadId":"41174","inReplyTo":"jwvr3hmwz1n.fsf-monnier+gmane.comp.version-control.git@gnu.org","subject":"Re: Can't diff against the 00000000 revision","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-12T18:52:41Z","receivedAt":"2016-01-12T18:52:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Monnier <monnier@iro.umontreal.ca> writes:\n\n>> And hopefully that explains why \"000000\" does not necessarily make a\n>> good placeholder for \"the empty thing\". There are multiple empty things,\n>> and it is not clear what:\n>\n>>   git diff 0000000 1234abcd\n>\n>> means. Is 0000000 a tree? A blob?\n>\n> Well, Git is the one who uses 000000 to refer to an empty thing, but\n> indeed it seems like it does inconsistently: it's sometimes used as the\n> \"empty blob\" and sometimes as an \"empty tree\".\n\nGit does not use 0*40 to refer to \"an empty thing\" at all.  It is\nused to denote a \"missing thing\".  A change to _create_ a new file\nand a diff to _modify_ an existing empty file are conceptually two\ndifferent things, and are shown differently.\n\nIt would be incorrect to say \"it used to be an empty blob\" by using\ne69de29bb2d1d on the left hand side of a patch that creates a new\nfile.\n"}]}