jdm
jdm

Reputation: 10130

Find later changes to a file in git

I checked out a specific revision of a repository with git checkout after git clone (git tells me that I have a detached head, if that is important).Now, this revision doesn't compile completely. It looks like some refactoring was only done partially, and I need to see what changes have been done later.

I've tried

git diff origin/master -- path/to/file

but that treated my file as completely new. I get a diff like:

diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
new file mode 100644
index 0000000..19e1244
--- /dev/null
+++ b/drivers/usb/core/driver.c
(complete contents of the file follows)

which doesn't help me at all. I've also tried variations of git log with no success.

Ideally, I'd like to see all diffs of changes made to the file at later dates (compared to what I have in my working copy). Once I've found interesting ones, I'd like to look at all the changes made in the specific revisions.

Note: Just checking out a later revision or branch wouldn't work in my case. The project uses different branches for different devices, and I've already got the latest commit for the device I'm working on. There are newer commits where the refactoring is complete, but they don't have all the device specific stuff I need.

Upvotes: 1

Views: 66

Answers (2)

patthoyts
patthoyts

Reputation: 33223

You are missing a <commit>:

$ git diff -h
usage: git diff [<options>] [<commit> [<commit>]] [--] [<path>...]

so if you provide the current commit (HEAD) and the one in the future it will show all differences affecting the specified file between your detached head and the remote head. ie:

git checkout HEAD~10
git diff HEAD origin/master -- path/to/file

moves me back 10 commits from my current position on master, creating a detached head and then shows all changes affecting that file between this current commit and the original commit. Of course git diff HEAD~10 HEAD -- path/to/file would have done it anyway from the usual case where HEAD == master.

Upvotes: 1

VonC
VonC

Reputation: 1328292

As in "Git: How can I reconcile detached HEAD with master/origin?", you could first make a temp branch where your detached HEAD is, and then:

git diff origin/master temp -- /path/to/file

Upvotes: 0

Related Questions