{"thread":{"id":"11522","subject":"git-diff across branches?","startedAt":"2008-01-08T08:44:14Z","lastAt":"2008-01-08T10:01:35Z","messageCount":3,"participants":["Gonzalo Garramuño","Jeff King","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"64708","messageId":"478337DE.7@advancedsl.com.ar","threadId":"11522","inReplyTo":null,"subject":"git-diff across branches?","fromName":"Gonzalo Garramuño","fromEmail":"ggarra@advancedsl.com.ar","sentAt":"2008-01-08T08:44:14Z","receivedAt":"2008-01-08T08:44:14Z","isPatch":false,"sender":{"key":"ggarra@advancedsl.com.ar","avatar":null},"body":"\nI was wondering if there was a way to make a git-diff across (local) \nbranches.\n\nSomething like:\n\n$ git-diff --branch test1 HEAD --branch test2 HEAD  file.cpp\n(would show a diff for file.cpp between test1 HEAD and test2 HEAD)\n\n\n\n-- \nGonzalo Garramuño\nggarra@advancedsl.com.ar\n\nAMD4400 - ASUS48N-E\nGeForce7300GT\nXubuntu Gutsy\n"},{"id":"64711","messageId":"20080108085705.GA4222@sigill.intra.peff.net","threadId":"11522","inReplyTo":"478337DE.7@advancedsl.com.ar","subject":"Re: git-diff across branches?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-08T08:57:06Z","receivedAt":"2008-01-08T08:57:06Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jan 08, 2008 at 05:44:14AM -0300, Gonzalo Garramuño wrote:\n\n> I was wondering if there was a way to make a git-diff across (local)  \n> branches.\n>\n> Something like:\n>\n> $ git-diff --branch test1 HEAD --branch test2 HEAD  file.cpp\n> (would show a diff for file.cpp between test1 HEAD and test2 HEAD)\n\nI think you are mistaken about how HEAD works; it is a pointer to a\nparticular branch. So there is no \"HEAD\" for test1; there is simply\ntest1, and from time to time your repository's HEAD points to test1.\n\nHowever, that makes things easier. You can simply do this:\n\n  git-diff test1 test2 file.cpp\n\nUnless you mean that you have two separate repositories, test1 and\ntest2. In which case each _does_ have its own HEAD, and you will have to\nfetch from one repo into the other to get your answer:\n\n  # go into one of the repos\n  cd test1\n  # fetch the 'master' ref from the other repo and store it in this repo\n  # using the name 'test2'\n  git fetch ../test2 master:test2\n  # now we can diff between them\n  git diff HEAD test2 file.cpp\n\n-Peff\n"},{"id":"64715","messageId":"m3wsqkmy22.fsf@roke.D-201","threadId":"11522","inReplyTo":"20080108085705.GA4222@sigill.intra.peff.net","subject":"Re: git-diff across branches?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-01-08T10:01:35Z","receivedAt":"2008-01-08T10:01:35Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Tue, Jan 08, 2008 at 05:44:14AM -0300, Gonzalo Garramuño wrote:\n> \n> > I was wondering if there was a way to make a git-diff across (local)  \n> > branches.\n> >\n> > Something like:\n> >\n> > $ git-diff --branch test1 HEAD --branch test2 HEAD  file.cpp\n> > (would show a diff for file.cpp between test1 HEAD and test2 HEAD)\n> \n> I think you are mistaken about how HEAD works; it is a pointer to a\n> particular branch. So there is no \"HEAD\" for test1; there is simply\n> test1, and from time to time your repository's HEAD points to test1.\n> \n> However, that makes things easier. You can simply do this:\n> \n>   git-diff test1 test2 file.cpp\n\nCanonically it is\n\n  # git diff test1 test2 -- file.cpp\n\nbut you can also use (for example if file was renamed)\n\n  # git diff test1:file.cpp test2:file.cpp\n \n> Unless you mean that you have two separate repositories, test1 and\n> test2. In which case each _does_ have its own HEAD, and you will have to\n> fetch from one repo into the other to get your answer:\n[cut]\n\nNot necessary. If those two repositories are on the same local\nfilesystem, you can use trick from GitTips:\n\n  http://git.or.cz/gitwiki/GitTips#head-9f79516c05f0c1b51945b848adb3dd1c5a2bf016\n\n  (assuming we are in test1, and ../test2 is relative path to test2)\n  # GIT_ALTERNATE_OBJECT_DIRECTORIES=../test2/.git/objects git diff-tree \\\n     $(GIT_DIR=../test2/.git git rev-parse --verify HEAD) HEAD\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}