Reputation: 19582
When I have a file, e.g. x.java
in Git, how can I see the differences from previous versions in Git?
In ClearCase we do a diff graphically or from the CLI? How do we do this in Git in CLI mode?
Upvotes: 0
Views: 311
Reputation: 1530
If you know the commit numbers and you want to compare this file between commits, you can do this command:
git diff <commit_old> <commit_new> x.java
Or you can also install and use any external tool for comparing:
git difftool x.java
For using difftool
, you should have installed and configured difftool on your local system.
Upvotes: 1
Reputation: 27536
git diff HEAD~1 x.java
This will compare your file with the same file one commit back
The most recent change of file would be
git log -n 1 -- x.java
, then you can copy commit hash a use it in git diff
.
You can also run GUI with gitk x.java
Upvotes: 2
Reputation: 155505
The simplest way to inspect when and how a particular file changed is with:
git log -p x.java
This will show you the commits that changed file.java
(ignoring the commits that don't) with diffs describing the changes to the file. After locating commit(s) of interest, you can produce diffs using:
git diff COMMIT_ID x.java # diff between COMMIT_ID and HEAD
git diff COMMIT_ID1 COMMIT_ID2 x.java # diff between COMMIT_ID1 and COMMIT_ID2
Upvotes: 0