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

Get a git diff without taking index into account

From
Eric Frederich <eric.frederich@gmail.com>
Date
Feb 18, 2015, 14:57 UTC
Message-ID
<CAAoZyYN-ohiq-Od=u-cd5FRH8=NpJNGS+zEo+NYgwAK7Kjaz_w@mail.gmail.com>

Some background. I'm trying to use Git as an object store for trees. I put trees into the repo and can retrieve them. I'm having issues with diffing these trees that I retrieve from the repo. If I use a "git checkout" the diffs seem to work but if I create the tree myself user lower level ls-tree and cat-file commands then the diff doesn't work. It seems to take the index into account.

Below is a complete working example.
Should be able to copy / paste line by line.
I am trying to run the diff of form:
  git diff [--options] <commit> [--] [<path>...]
where it says it does a diff from working tree to a commit

Maybe git is interpreting my command as one of the other forms? Can someone help me understand what is going on?

# # EXAMPLE #

# cleanup and create dummy data rm -rf /tmp/mydatastore && mkdir -p /tmp/mydatastore rm -rf /tmp/test /tmp/test2 && mkdir -p /tmp/test/d1 /tmp/test2 echo "this is f1" > /tmp/test/f1 echo "this is f2" > /tmp/test/d1/f2

# create a new branch called test with data from /tmp/test git --git-dir=/tmp/mydatastore/.db init --bare git --git-dir=/tmp/mydatastore/.db hash-object -w /tmp/test/d1/f2 /tmp/test/f1 echo -e "100644 blob c837441e09d13d3a0a2d906d7c3813adda504833\tf2" | git --git-dir=/tmp/mydatastore/.db mktree --batch echo -e "100644 blob 11ac5613caf504eec18b2e60f1e6b3c598b085eb\tf1\n40755 tree 055f1133fbc9872f3093cca5f182b16611e6789a\td1" | git --git-dir=/tmp/mydatastore/.db mktree commit_sha=`git --git-dir=/tmp/mydatastore/.db commit-tree -m "initial commit" c427094b22e74d1eaeebdc9e49e6790b5b6a706a` git --git-dir=/tmp/mydatastore/.db update-ref refs/heads/test $commit_sha

# why does this show diffs? git --git-dir=/tmp/mydatastore/.db --work-tree=/tmp/test diff $commit_sha

# after doing a checkout somewhere else it doesn't show any diffs git --git-dir=/tmp/mydatastore/.db --work-tree=/tmp/test2 checkout test . git --git-dir=/tmp/mydatastore/.db --work-tree=/tmp/test diff $commit_sha

# remove the index and it shows diffs again rm /tmp/mydatastore/.db/index git --git-dir=/tmp/mydatastore/.db --work-tree=/tmp/test diff $commit_sha

# it was my understanding from "git help diff" that this form of diff is supposed to # compare a work tree against a commit or branch and not take into account the index. # Clearly it takes into account the index because we get different results with and without it

Next: Eric Frederich
Message 1 of 11 in “Get a git diff without taking index into account”
  1. Eric FrederichFeb 18, 2015
  2. Eric FrederichFeb 18, 2015
  3. Junio C HamanoFeb 18, 2015
  4. Eric FrederichFeb 18, 2015
  5. Junio C HamanoFeb 18, 2015
  6. Eric FrederichFeb 18, 2015
  7. Jeff KingFeb 18, 2015
  8. Eric FrederichFeb 18, 2015
  9. Eric FrederichFeb 18, 2015
  10. Junio C HamanoFeb 18, 2015
  11. Jeff KingFeb 18, 2015

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.