git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-diff across branches?

From
Jakub Narebski <jnareb@gmail.com>
Date
Jan 8, 2008, 10:01 UTC
Message-ID
<m3wsqkmy22.fsf@roke.D-201>
In-Reply-To
<20080108085705.GA4222@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 17 quoted lines
> On Tue, Jan 08, 2008 at 05:44:14AM -0300, Gonzalo Garramuño wrote:
> 
> > I was wondering if there was a way to make a git-diff across (local)  
> > branches.
> >
> > Something like:
> >
> > $ git-diff --branch test1 HEAD --branch test2 HEAD  file.cpp
> > (would show a diff for file.cpp between test1 HEAD and test2 HEAD)
> 
> I think you are mistaken about how HEAD works; it is a pointer to a
> particular branch. So there is no "HEAD" for test1; there is simply
> test1, and from time to time your repository's HEAD points to test1.
> 
> However, that makes things easier. You can simply do this:
> 
>   git-diff test1 test2 file.cpp
Canonically it is
  # git diff test1 test2 -- file.cpp
but you can also use (for example if file was renamed)
  # git diff test1:file.cpp test2:file.cpp
 
> Unless you mean that you have two separate repositories, test1 and
> test2. In which case each _does_ have its own HEAD, and you will have to
> fetch from one repo into the other to get your answer:
[cut]

Not necessary. If those two repositories are on the same local filesystem, you can use trick from GitTips:

  http://git.or.cz/gitwiki/GitTips#head-9f79516c05f0c1b51945b848adb3dd1c5a2bf016
  (assuming we are in test1, and ../test2 is relative path to test2)
  # GIT_ALTERNATE_OBJECT_DIRECTORIES=../test2/.git/objects git diff-tree \
     $(GIT_DIR=../test2/.git git rev-parse --verify HEAD) HEAD
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Jeff King
Message 3 of 3 in “git-diff across branches?”
  1. Gonzalo GarramuñoJan 8, 2008
  2. Jeff KingJan 8, 2008
  3. Jakub NarebskiJan 8, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.