Jason S
Jason S

Reputation: 189876

git: determine whether a given file changed between revision hashes A and B?

Is there an easy way in Git to determine whether a given file changed between revision hashes A and B?

I know I can do this easily if I can determine the revision hashes A' and B', where A'=predchange(A, path) and B'=predchange(B, path), where predchange(X, path) is the most recent parent of X (or X itself) where the given path was changed. Then I just check whether A' == B'.

Upvotes: 0

Views: 51

Answers (3)

craig65535
craig65535

Reputation: 3581

git diff <A> <B> -- <path> | wc -l

0 means the file was not changed.

Upvotes: 0

masonk
masonk

Reputation: 9798

git diff [--stat] A..B -- path/to/file

With --stat, it simply shows a one-line summary of the changes. Without, it shows the actual diff.

The A..B syntax is a revision range. It scans as "All commits reachable from B, but not from A". When you pass a revision range to diff, it shows diffs from all commits in the range. A and B are "commitish" - either SHA1's identifying commits, refs or tags, HEAD, or any of the previous combined with the special selectors such as ^.

Upvotes: 3

alex
alex

Reputation: 490637

Yes, you can use git diff with a range.

git diff HEAD^.. file.txt

If you see less empty, nothing has changed.

Upvotes: 1

Related Questions