{"thread":{"id":"23716","subject":"Any way to get complete diff up to a tag?","startedAt":"2010-05-06T09:27:40Z","lastAt":"2010-05-07T16:35:41Z","messageCount":13,"participants":["Peter Kjellerstedt","Bert Wesarg","Björn Steinbrink","Santi Béjar","Johannes Sixt","Knittl","Linus Torvalds","Greg Troxel"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"141058","messageId":"A612847CFE53224C91B23E3A5B48BAC74482E50D9F@xmail3.se.axis.com","threadId":"23716","inReplyTo":null,"subject":"Any way to get complete diff up to a tag?","fromName":"Peter Kjellerstedt","fromEmail":"peter.kjellerstedt@axis.com","sentAt":"2010-05-06T09:27:40Z","receivedAt":"2010-05-06T09:27:40Z","isPatch":false,"sender":{"key":"peter.kjellerstedt@axis.com","avatar":"https://gravatar.com/avatar/6d5a0182283c8eccd7b134a54dbfd5f30038f3ad4d38b96f424884b614a61ca2?d=mp&s=160"},"body":"If I use\n\n$ git diff v1.7.1..\n\nI get a diff for everything that has happened after the v1.7.1\nrelease (up to HEAD). Is there a way to do the opposite, i.e.,\nget everything (including the initial commit) up to and including \nv1.7.1? I first tried  \n\n$ git diff ..v1.7.1\n\nbut it gave me the reverse of the above, which I later found out \nwas due to it being the same as\n\n$ git diff HEAD..v1.7.1\n\nwhich of course does not yield the result I want. \n\nIf I use\n\n$ git diff $(git rev-list --reverse v1.7.1 |head -1)..v1.7.1\n\nI almost get what I want, but the initial commit is still missing.\nIs there any way to get that initial commit included in the diff?\n\nBasically, what I think I am asking for is a way to specify the \nempty parent of the initial commit, i.e., where v1.7.1~1000000 would\nend up. I can see this being useful in at least one other case as \nwell, namely when doing an interactive rebase to allow the initial\ncommit to be rebased (something I have wanted to do a couple of \ntimes...)\n\n//Peter\n"},{"id":"141059","messageId":"AANLkTim3MnUdYDfMuIC-jPcgzvMJuRqupVaaGPmJyPjP@mail.gmail.com","threadId":"23716","inReplyTo":"A612847CFE53224C91B23E3A5B48BAC74482E50D9F@xmail3.se.axis.com","subject":"Re: Any way to get complete diff up to a tag?","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2010-05-06T09:42:09Z","receivedAt":"2010-05-06T09:42:09Z","isPatch":false,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Thu, May 6, 2010 at 11:27, Peter Kjellerstedt\n<peter.kjellerstedt@axis.com> wrote:\n> I almost get what I want, but the initial commit is still missing.\n> Is there any way to get that initial commit included in the diff?\n\ngit diff-tree -p 4b825dc642cb6eb9a060e54bf8d69288fbee4904 v1.7.1^{tree}\n\nBert\n"},{"id":"141060","messageId":"20100506094212.GB9921@atjola.homenet","threadId":"23716","inReplyTo":"A612847CFE53224C91B23E3A5B48BAC74482E50D9F@xmail3.se.axis.com","subject":"Re: Any way to get complete diff up to a tag?","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2010-05-06T09:42:12Z","receivedAt":"2010-05-06T09:42:12Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2010.05.06 11:27:40 +0200, Peter Kjellerstedt wrote:\n> If I use\n> \n> $ git diff $(git rev-list --reverse v1.7.1 |head -1)..v1.7.1\n> \n> I almost get what I want, but the initial commit is still missing.\n> Is there any way to get that initial commit included in the diff?\n\ngit internally knows about the empty tree, so you can use:\ngit diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 v1.7.1\n\nBjörn\n"},{"id":"141064","messageId":"A612847CFE53224C91B23E3A5B48BAC74482E50DE7@xmail3.se.axis.com","threadId":"23716","inReplyTo":"20100506094212.GB9921@atjola.homenet","subject":"RE: Any way to get complete diff up to a tag?","fromName":"Peter Kjellerstedt","fromEmail":"peter.kjellerstedt@axis.com","sentAt":"2010-05-06T11:20:18Z","receivedAt":"2010-05-06T11:20:18Z","isPatch":false,"sender":{"key":"peter.kjellerstedt@axis.com","avatar":"https://gravatar.com/avatar/6d5a0182283c8eccd7b134a54dbfd5f30038f3ad4d38b96f424884b614a61ca2?d=mp&s=160"},"body":"> -----Original Message-----\n> From: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On\n> Behalf Of Björn Steinbrink\n> Sent: den 6 maj 2010 11:42\n> To: Peter Kjellerstedt\n> Cc: git@vger.kernel.org\n> Subject: Re: Any way to get complete diff up to a tag?\n> \n> On 2010.05.06 11:27:40 +0200, Peter Kjellerstedt wrote:\n> > If I use\n> >\n> > $ git diff $(git rev-list --reverse v1.7.1 |head -1)..v1.7.1\n> >\n> > I almost get what I want, but the initial commit is still missing.\n> > Is there any way to get that initial commit included in the diff?\n> \n> git internally knows about the empty tree, so you can use:\n> git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 v1.7.1\n> \n> Björn\n\nThank you, that was useful. However, I need to be able to do this\nfor an arbitrary repository, and that SHA seems to be specific for \nthe git repository. How do I get the SHA for the empty tree in an \narbitrary repository?\n\n//Peter\n"},{"id":"141068","messageId":"h2iadf1fd3d1005060600x95fc0e34m91b1697fc6f1789e@mail.gmail.com","threadId":"23716","inReplyTo":"A612847CFE53224C91B23E3A5B48BAC74482E50DE7@xmail3.se.axis.com","subject":"Re: Any way to get complete diff up to a tag?","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2010-05-06T13:00:50Z","receivedAt":"2010-05-06T13:00:50Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2010/5/6 Peter Kjellerstedt <peter.kjellerstedt@axis.com>:\n>> -----Original Message-----\n>> From: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On\n>> Behalf Of Björn Steinbrink\n>>\n>> On 2010.05.06 11:27:40 +0200, Peter Kjellerstedt wrote:\n>> > If I use\n>> >\n>> > $ git diff $(git rev-list --reverse v1.7.1 |head -1)..v1.7.1\n>> >\n>> > I almost get what I want, but the initial commit is still missing.\n>> > Is there any way to get that initial commit included in the diff?\n>>\n>> git internally knows about the empty tree, so you can use:\n>> git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 v1.7.1\n>>\n>> Björn\n>\n> Thank you, that was useful. However, I need to be able to do this\n> for an arbitrary repository, and that SHA seems to be specific for\n> the git repository. How do I get the SHA for the empty tree in an\n> arbitrary repository?\n\nIt is not specific for the git repository, there is only one SHA1 for\nthe empty tree. But it is hard-coded in git itself since 1.5.5. If you\nuse an older git you have to create it yourself.\n\nSanti\n"},{"id":"141069","messageId":"4BE2BE2C.8050403@viscovery.net","threadId":"23716","inReplyTo":"A612847CFE53224C91B23E3A5B48BAC74482E50DE7@xmail3.se.axis.com","subject":"Re: Any way to get complete diff up to a tag?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-05-06T13:03:40Z","receivedAt":"2010-05-06T13:03:40Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 5/6/2010 13:20, schrieb Peter Kjellerstedt:\n> Björn Steinbrink\n>> git internally knows about the empty tree, so you can use:\n>> git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 v1.7.1\n>>\n>> Björn\n> \n> Thank you, that was useful. However, I need to be able to do this\n> for an arbitrary repository, and that SHA seems to be specific for \n> the git repository. How do I get the SHA for the empty tree in an \n> arbitrary repository?\n\nAha, so you think Björn et.al. were able to guess the SHA1 for your\nspecific repository? ;)\n\nNo, the empty tree is the empty tree, and its name is as cited above, no\nmatter where in the universe you are.\n\n-- Hannes\n"},{"id":"141070","messageId":"A612847CFE53224C91B23E3A5B48BAC74482E50F03@xmail3.se.axis.com","threadId":"23716","inReplyTo":"4BE2BE2C.8050403@viscovery.net","subject":"RE: Any way to get complete diff up to a tag?","fromName":"Peter Kjellerstedt","fromEmail":"peter.kjellerstedt@axis.com","sentAt":"2010-05-06T15:09:57Z","receivedAt":"2010-05-06T15:09:57Z","isPatch":false,"sender":{"key":"peter.kjellerstedt@axis.com","avatar":"https://gravatar.com/avatar/6d5a0182283c8eccd7b134a54dbfd5f30038f3ad4d38b96f424884b614a61ca2?d=mp&s=160"},"body":"> -----Original Message-----\n> From: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On\n> Behalf Of Johannes Sixt\n> Sent: den 6 maj 2010 15:04\n> To: Peter Kjellerstedt\n> Cc: Björn Steinbrink; git@vger.kernel.org\n> Subject: Re: Any way to get complete diff up to a tag?\n> \n> Am 5/6/2010 13:20, schrieb Peter Kjellerstedt:\n> > Björn Steinbrink\n> >> git internally knows about the empty tree, so you can use:\n> >> git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 v1.7.1\n> >>\n> >> Björn\n> >\n> > Thank you, that was useful. However, I need to be able to do this\n> > for an arbitrary repository, and that SHA seems to be specific for\n> > the git repository. How do I get the SHA for the empty tree in an\n> > arbitrary repository?\n> \n> Aha, so you think Björn et.al. were able to guess the SHA1 for your\n> specific repository? ;)\n\nNo, not really, but I could not understand why it worked when I\ntested it in my clone of git itself, but not in another git repository.\n\n> No, the empty tree is the empty tree, and its name is as cited above,\n> no matter where in the universe you are.\n> \n> -- Hannes\n\nWell, I figured out my mistake. I had abbreviated the SHA1 since I\ntyped it in manually, and it worked fine in git's own repository, \nbut not in another repository. But when I used the full SHA1 it \nworked in both. So I guess the empty dir SHA1 hardcoded in git just \nhappened to be the SHA1 for the empty dir in git's own repository...\n\nSince the 4b825dc642cb6eb9a060e54bf8d69288fbee4904 SHA1 is somewhat\ncumbersome to remember, wouldn't it be an idea to give it some kind \nof alias or mnemonic? E.g., something like @~ (or some other mix of \nodd characters which do not clash with all the other similar \nconstructs already used for references).\n\nAnyway, thanks all for the help.\n//Peter\n"},{"id":"141071","messageId":"20100506152717.GA12230@atjola.homenet","threadId":"23716","inReplyTo":"A612847CFE53224C91B23E3A5B48BAC74482E50F03@xmail3.se.axis.com","subject":"Re: Any way to get complete diff up to a tag?","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2010-05-06T15:27:17Z","receivedAt":"2010-05-06T15:27:17Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2010.05.06 17:09:57 +0200, Peter Kjellerstedt wrote:\n> \n> Well, I figured out my mistake. I had abbreviated the SHA1 since I\n> typed it in manually, and it worked fine in git's own repository, \n> but not in another repository. But when I used the full SHA1 it \n> worked in both. So I guess the empty dir SHA1 hardcoded in git just \n> happened to be the SHA1 for the empty dir in git's own repository...\n\nNo, there can be only one SHA1 for the empty tree. It's the SHA1 hash of\nthe object, and the empty tree is the empty tree, always.\n\ngit.git just happens to actually contain that object, so the abbreviated\nhash works, because git can find the object and doesn't actually need\nthe hardcoded built-in empty tree (which is only used when the full hash\nis given).\n\nBjörn\n"},{"id":"141073","messageId":"AANLkTilOOYlrQ5hfgxFnCIG4Qp5RE_EbfzP6vkfqBAJM@mail.gmail.com","threadId":"23716","inReplyTo":"A612847CFE53224C91B23E3A5B48BAC74482E50D9F@xmail3.se.axis.com","subject":"Re: Any way to get complete diff up to a tag?","fromName":"Knittl","fromEmail":"knittl89@googlemail.com","sentAt":"2010-05-06T15:43:53Z","receivedAt":"2010-05-06T15:43:53Z","isPatch":false,"sender":{"key":"knittl89@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/2149217?v=4"},"body":"On Thu, May 6, 2010 at 11:27 AM, Peter Kjellerstedt\n<peter.kjellerstedt@axis.com> wrote:\n> Basically, what I think I am asking for is a way to specify the\n> empty parent of the initial commit, i.e., where v1.7.1~1000000 would\n> end up. I can see this being useful in at least one other case as\n> well, namely when doing an interactive rebase to allow the initial\n> commit to be rebased (something I have wanted to do a couple of\n> times...)\n\n\nwait, let me get this straight. you want to diff some tag against the\nempty parent of the root commit (empty tree)?\n\nwhich in turn means you will get a diff, where all lines in all files\nexisting in the tree that tag references are added. all files get\nbasically prefixed with + and have header information (filename). what\npurpose has such a diff?\n\nregards, daniel\n\n-- \ntyped with http://neo-layout.org\nmyFtPhp -- visit http://myftphp.sf.net -- v. 0.4.7 released!\n"},{"id":"141074","messageId":"alpine.LFD.2.00.1005060955000.901@i5.linux-foundation.org","threadId":"23716","inReplyTo":"A612847CFE53224C91B23E3A5B48BAC74482E50F03@xmail3.se.axis.com","subject":"RE: Any way to get complete diff up to a tag?","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2010-05-06T17:08:39Z","receivedAt":"2010-05-06T17:08:39Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 6 May 2010, Peter Kjellerstedt wrote:\n> \n> Since the 4b825dc642cb6eb9a060e54bf8d69288fbee4904 SHA1 is somewhat\n> cumbersome to remember, wouldn't it be an idea to give it some kind \n> of alias or mnemonic? E.g., something like @~ (or some other mix of \n> odd characters which do not clash with all the other similar \n> constructs already used for references).\n\nWell, you don't strictly speaking have to \"remember\" it, you can always \njust re-generate it. The most straightforward way to do that is probably\n\n\tgit hash-object -t tree --stdin < /dev/null\n\nalthough I admit that maybe we could have some syntax for \"git diff\" that \nwould do the \"diff against empty tree\" automatically. It does seem to be \nconceptually a reasonable thing to do.\n\nFor example, right now if you give \"git diff\" a single SHA1, it will work \nagainst the working tree. Except if you add \"--cached\", to say that you \nwant the diff against the index. I don't think it would be in any way \n_wrong_ to make \"--root\" mean that you want it against an empty tree.\n\n[ We already accept \"--root\", but it has no meaning for \"git diff\" with a \n  single SHA1. It matters for showing the root commit for 'git-diff-tree'.\n\n  And means something totally different for git-format-patch ]\n\nSo we certainly _could_ do something like\n\n\tgit diff --root <treeish>\n\nand make it do what you want. That said, the \"empty tree\" thing works for \nall versions of git (well, some older versions of git need the actual \nobject, but you could always use \"-w\" on that git-hash-object command \nline, and then it really should work for every git version).\n\n\t\t\tLinus\n"},{"id":"141077","messageId":"rmiwrvgana0.fsf@fnord.ir.bbn.com","threadId":"23716","inReplyTo":"alpine.LFD.2.00.1005060955000.901@i5.linux-foundation.org","subject":"Re: Any way to get complete diff up to a tag?","fromName":"Greg Troxel","fromEmail":"gdt@ir.bbn.com","sentAt":"2010-05-06T18:38:31Z","receivedAt":"2010-05-06T18:38:31Z","isPatch":false,"sender":{"key":"gdt@ir.bbn.com","avatar":null},"body":"\nLinus Torvalds <torvalds@linux-foundation.org> writes:\n\n> Well, you don't strictly speaking have to \"remember\" it, you can always \n> just re-generate it. The most straightforward way to do that is probably\n>\n> \tgit hash-object -t tree --stdin < /dev/null\n>\n> although I admit that maybe we could have some syntax for \"git diff\" that \n> would do the \"diff against empty tree\" automatically. It does seem to be \n> conceptually a reasonable thing to do.\n\nHow about \n\n  git diff empty..\n\nas if empty is a tag for the empty revision?  It works for 'git\ncheckout' already.\n\n"},{"id":"141108","messageId":"A612847CFE53224C91B23E3A5B48BAC744829D68C7@xmail3.se.axis.com","threadId":"23716","inReplyTo":"AANLkTilOOYlrQ5hfgxFnCIG4Qp5RE_EbfzP6vkfqBAJM@mail.gmail.com","subject":"RE: Any way to get complete diff up to a tag?","fromName":"Peter Kjellerstedt","fromEmail":"peter.kjellerstedt@axis.com","sentAt":"2010-05-07T04:17:51Z","receivedAt":"2010-05-07T04:17:51Z","isPatch":false,"sender":{"key":"peter.kjellerstedt@axis.com","avatar":"https://gravatar.com/avatar/6d5a0182283c8eccd7b134a54dbfd5f30038f3ad4d38b96f424884b614a61ca2?d=mp&s=160"},"body":"> -----Original Message-----\n> From: git-owner@vger.kernel.org\n> [mailto:git-owner@vger.kernel.org] On Behalf Of Knittl\n> Sent: den 6 maj 2010 17:44\n> To: Peter Kjellerstedt\n> Cc: git@vger.kernel.org\n> Subject: Re: Any way to get complete diff up to a tag?\n>\n> On Thu, May 6, 2010 at 11:27 AM, Peter Kjellerstedt\n> <peter.kjellerstedt@axis.com> wrote:\n> > Basically, what I think I am asking for is a way to specify the\n> > empty parent of the initial commit, i.e., where v1.7.1~1000000 would\n> > end up. I can see this being useful in at least one other case as\n> > well, namely when doing an interactive rebase to allow the initial\n> > commit to be rebased (something I have wanted to do a couple of\n> > times...)\n>\n> wait, let me get this straight. you want to diff some tag against the\n> empty parent of the root commit (empty tree)?\n>\n> which in turn means you will get a diff, where all lines in all files\n> existing in the tree that tag references are added. all files get\n> basically prefixed with + and have header information (filename). what\n> purpose has such a diff?\n>\n> regards, daniel\n\nWell, I can see a couple of purposes, but in my case I have a tool\npost-processing the generated diff. And to it there is no difference\nregarding what point was used as the start of the diff, whether it\nwas the empty tree (i.e., a diff containing everything), some commit\nin the middle, or the last commit (i.e., an emptry diff). All it\nwants is a diff.\n\n//Peter\n"},{"id":"141128","messageId":"A612847CFE53224C91B23E3A5B48BAC74482E5113B@xmail3.se.axis.com","threadId":"23716","inReplyTo":"alpine.LFD.2.00.1005060955000.901@i5.linux-foundation.org","subject":"RE: Any way to get complete diff up to a tag?","fromName":"Peter Kjellerstedt","fromEmail":"peter.kjellerstedt@axis.com","sentAt":"2010-05-07T16:35:41Z","receivedAt":"2010-05-07T16:35:41Z","isPatch":false,"sender":{"key":"peter.kjellerstedt@axis.com","avatar":"https://gravatar.com/avatar/6d5a0182283c8eccd7b134a54dbfd5f30038f3ad4d38b96f424884b614a61ca2?d=mp&s=160"},"body":"> -----Original Message-----\n> From: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On\n> Behalf Of Linus Torvalds\n> Sent: den 6 maj 2010 19:09\n> To: Peter Kjellerstedt\n> Cc: Johannes Sixt; git@vger.kernel.org; Björn Steinbrink\n> Subject: RE: Any way to get complete diff up to a tag?\n> \n> On Thu, 6 May 2010, Peter Kjellerstedt wrote:\n> >\n> > Since the 4b825dc642cb6eb9a060e54bf8d69288fbee4904 SHA1 is somewhat\n> > cumbersome to remember, wouldn't it be an idea to give it some kind\n> > of alias or mnemonic? E.g., something like @~ (or some other mix of\n> > odd characters which do not clash with all the other similar\n> > constructs already used for references).\n> \n> Well, you don't strictly speaking have to \"remember\" it, you can always\n> just re-generate it. The most straightforward way to do that is\n> probably\n> \n> \tgit hash-object -t tree --stdin < /dev/null\n\nThank you, that is good to know.\n\n> although I admit that maybe we could have some syntax for \"git diff\"\n> that would do the \"diff against empty tree\" automatically. It does \n> seem to be conceptually a reasonable thing to do.\n> \n> For example, right now if you give \"git diff\" a single SHA1, it will\n> work against the working tree. Except if you add \"--cached\", to say \n> that you want the diff against the index. I don't think it would be in \n> any way _wrong_ to make \"--root\" mean that you want it against an \n> empty tree.\n> \n> [ We already accept \"--root\", but it has no meaning for \"git diff\" \n>   with a single SHA1. It matters for showing the root commit for \n>   'git-diff-tree'.\n> \n>   And means something totally different for git-format-patch ]\n> \n> So we certainly _could_ do something like\n> \n> \tgit diff --root <treeish>\n\nI went ahead and implemented support for --root as an option to git \ndiff (patch attached for reference). However, I then realized that \nthere are probably more commands that would benefit from the same \nsupport, e.g., git diff-index. Then I thought about git diff-tree\nand realized that it could also benefit from my version of --root,\nbut as you mentioned above, it already has a --root option with\na different semantic... I also figured it would be a hassle for me \nto find all commands who can use a --root option, not knowing the \ninternals of git well enough yet.\n\nSo I then went back to my original idea of making an alias for the\nempty tree, and came up with a two line patch which I will send as\na separate patch, and see what you guys think of the idea.\n\n> and make it do what you want. That said, the \"empty tree\" thing works\n> for all versions of git (well, some older versions of git need the \n> actual object, but you could always use \"-w\" on that git-hash-object \n> command line, and then it really should work for every git version).\n> \n> \t\t\tLinus\n\n//Peter\n\n\n\nFrom d9d482db98aa3ff3545cf66a8f851cc459b0eacd Mon Sep 17 00:00:00 2001\nFrom: Peter Kjellerstedt <pkj@axis.com>\nDate: Fri, 7 May 2010 17:11:19 +0200\nSubject: [PATCH] diff: Make git diff support the --root option\n\nUsing 'git diff --root <tree-ish>' will give all the changes between\nthe empty tree and <tree-ish>. It is also possible to use 'git diff\n--root --cached' to get all changes between the empty tree and the\ncurrent index.\n\nSigned-off-by: Peter Kjellerstedt <pkj@axis.com>\n---\n builtin/diff.c |   28 ++++++++++++++++++++++------\n revision.c     |   12 ++++++++++++\n revision.h     |    1 +\n 3 files changed, 35 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex ffcdd05..8da59dd 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -253,6 +253,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \tconst char *path = NULL;\n \tstruct blobinfo blob[2];\n \tint nongit;\n+\tint cached = 0;\n \tint result = 0;\n \n \t/*\n@@ -316,10 +317,10 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \t\tsetup_pager();\n \n \t/*\n-\t * Do we have --cached and not have a pending object, then\n-\t * default to HEAD by hand.  Eek.\n+\t * If we have --cached and/or --root we may need to add the empty tree\n+\t * or HEAD by hand.  Eek.\n \t */\n-\tif (!rev.pending.nr) {\n+\tif (rev.pending.nr <= 1) {\n \t\tint i;\n \t\tfor (i = 1; i < argc; i++) {\n \t\t\tconst char *arg = argv[i];\n@@ -327,14 +328,29 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \t\t\t\tbreak;\n \t\t\telse if (!strcmp(arg, \"--cached\") ||\n \t\t\t\t !strcmp(arg, \"--staged\")) {\n-\t\t\t\tadd_head_to_pending(&rev);\n-\t\t\t\tif (!rev.pending.nr)\n-\t\t\t\t\tdie(\"No HEAD commit to compare with (yet)\");\n+\t\t\t\tcached = 1;\n \t\t\t\tbreak;\n \t\t\t}\n \t\t}\n \t}\n \n+\tif (!rev.pending.nr) {\n+\t\tif (rev.show_root_diff) {\n+\t\t\tadd_empty_tree_to_pending(&rev);\n+\t\t\tif (!rev.pending.nr)\n+\t\t\t\tdie(\"No empty tree to compare with\");\n+\t\t} else if (cached) {\n+\t\t\tadd_head_to_pending(&rev);\n+\t\t\tif (!rev.pending.nr)\n+\t\t\t\tdie(\"No HEAD commit to compare with (yet)\");\n+\t\t}\n+\t} else if (rev.pending.nr == 1 && rev.show_root_diff && !cached) {\n+\t\tadd_empty_tree_to_pending(&rev);\n+\t\tif (rev.pending.nr != 2)\n+\t\t\tdie(\"No empty tree to compare with\");\n+\t\trev.diffopt.flags ^= DIFF_OPT_REVERSE_DIFF;\n+\t}\n+\n \tfor (i = 0; i < rev.pending.nr; i++) {\n \t\tstruct object_array_entry *list = rev.pending.objects+i;\n \t\tstruct object *obj = list->item;\ndiff --git a/revision.c b/revision.c\nindex f4b8b38..c3a78dc 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -169,6 +169,18 @@ void add_head_to_pending(struct rev_info *revs)\n \tadd_pending_object(revs, obj, \"HEAD\");\n }\n \n+void add_empty_tree_to_pending(struct rev_info *revs)\n+{\n+\tunsigned char sha1[20];\n+\tstruct object *obj;\n+\tif (get_sha1(EMPTY_TREE_SHA1_HEX, sha1))\n+\t\treturn;\n+\tobj = parse_object(sha1);\n+\tif (!obj)\n+\t\treturn;\n+\tadd_pending_object(revs, obj, EMPTY_TREE_SHA1_HEX);\n+}\n+\n static struct object *get_reference(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags)\n {\n \tstruct object *object;\ndiff --git a/revision.h b/revision.h\nindex 568f1c9..e1a7d9d 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -176,6 +176,7 @@ extern void add_object(struct object *obj,\n extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name);\n \n extern void add_head_to_pending(struct rev_info *);\n+extern void add_empty_tree_to_pending(struct rev_info *revs);\n \n enum commit_action {\n \tcommit_ignore,\n-- \n1.7.0.1\n\n"}]}