Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (27.5k points)

I am using Git on Ubuntu 10.04 (Lucid Lynx).

I have made some commits to my master.

However, I want to get the difference between these commits. All of them are on my master branch.

For example:

commit dj374

made changes

commit y4746

made changes

commit k73ud

made changes

I want to get the difference between k73ud and dj374. However, when I did the following I couldn't see the changes I made in k73ud.

git diff k73ud..dj374 > master.patch

1 Answer

0 votes
by (19.4k points)

Try the following command: 

$ git diff k73ud^..dj374

In order to make sure that all changes of k73ud are included in the resulting diff.

The command 'git diff' compares two endpoints (instead of a commit range). 

As we wanted to see the changes introduced by k73ud, we need to notice the differences between the first parent commit of k73ud k73ud^ (or k73ud^1 or k73ud~).

The results will include changes made since k73ud parent (meaning including changes from k73ud itself), instead of changes introduced since k73ud (up to dj374).

Alternatively, you can try:

$ git diff oldCommit..newCommit

$ git diff k73ud..dj374 

and (1 space, not more):

$ git diff oldCommit newCommit

$ git diff k73ud dj374

If you want to retrieve only file names:

$ git diff k73ud dj374 --name-only

And you can get changes applied to another branch:

$ git diff k73ud dj374 > my.patch

$ git apply my.patch

Browse Categories

...