I want to compare two versions of a file (which exist at different paths) at different commits in git. I don't want the diff, I simply want to know if the contents and modes are the same. The documentation for diff-files doesn't indicate any meaning for return values. I don't see something similar to cmp(1) in git. Is there another plumbing tool to do this or does diff-files have return values that express this?
Asked
Active
Viewed 516 times
0
-
I suppose if the files are the same they should be the same blob. Does the blob hash include the mode? – David Greene Jul 21 '16 at 20:59
2 Answers
3
git diff --exit-code <commit> <commit>
I believe you looking for.
Its almost down the bottom in the docs https://git-scm.com/docs/git-diff
Or
git diff --quiet <commit> <commit>
If your purely interested in the exit code and nothing more (no console output)

clinux
- 2,984
- 2
- 23
- 26
0
git ls-tree <commit> -- <path>
outputs
<mode> SP <type> SP <object> TAB <file>
<mode>
is the file mode. <object>
is the sha1 that indicates the content.
Compare the modes and objects.
<object>
here can be named in another way
<commit>:<path>
So git rev-parse <commit>:<path>
can output the sha1 of the blob or the tree. Comparing the two sha1, we can see if the contents are the same or not.

ElpieKay
- 27,194
- 6
- 32
- 53