As in the title, I want to have a diff file for a certain folder between the master branch and a branch I have created.
Asked
Active
Viewed 9.4k times
2 Answers
325
You can use
git diff master..yourbranch -- path/to/folder

jolivier
- 7,380
- 3
- 29
- 47
-
Can I specify a certain committer and how to extract this diff to a txt file. – Wazery Aug 25 '12 at 16:25
-
what do you mean by extracting a certain commiter? retrieve the last commit of this person? To write this diff to a file you juste redirect the output like this ` git diff master..yourbranch path/to/file > filename – jolivier Aug 25 '12 at 16:27
-
I mean to extract only commits added by a certain author in my branch. – Wazery Aug 25 '12 at 16:30
-
1but between which ones do you want to diff? the last one? – jolivier Aug 25 '12 at 16:48
-
I need a diff for a certain author commits between master and mybranch – Wazery Aug 25 '12 at 16:50
-
10I get `fatal: bad revision 'master..develop_content'` – niklas Sep 20 '16 at 10:02
-
7Make sure that you have the branches checked out locally if you get that error. – Karl Henselin Mar 07 '19 at 23:08
-
1Alternatively, `git fetch` and `git diff master..origin/develop_content` – Florian Wendelborn Feb 22 '20 at 19:13
-
I tried this command but it is not showing all differences. Only new file is shown. – Shashank Bhatt Aug 20 '20 at 06:45
-
@ShashankBhatt `git diff` has a lot of options that you can learn via `git help diff`. In your case maybe you staged some of the difference and need to add `--staged` to the command in the answer to see them. – jolivier Aug 28 '20 at 12:37
-
1You now need to add two hyphens to separate the branches from the path: `git diff master..yourbranch -- path/to/folder` – Doug DesCombaz Jun 29 '22 at 16:05
13
git diff
compares trees (as in hierarchies of source files at two different points in time), so it can't extract the changes done by a certain author. If you want to see what changes a user committed, then you need git log
.
Does this solve your need?
git log --author=jdoe oldbranch..newbranch -p -- path/to/subdirectory > myChangesInSubdirectory.patch
This lists each commit done by jdoe between the two commits, printing them as a patch instead of the usual commit summary, limiting only to commits that have changes in the target subdirectory, and redirects the output to a file.

Sergiu Dumitriu
- 11,455
- 3
- 39
- 62