Differences for a certain folder between git branches

77,178

Solution 1

You can use

git diff master..yourbranch -- path/to/folder

Solution 2

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.

Share:
77,178
Wazery
Author by

Wazery

Software Engineer | ex-GSoCer《2012》| GSoC 2013 Mentor | KDE Developer | Ubuntu Official Member | Rails Contributor | CS Graduate | Fan of {OpenSource, SciFi, Tennis, Electro Music}. Areas of familiarity: Web Programming (Ruby on Rails, CSS, HTML, JavaScript) C/C++ Qt Linkedin: wazery Github: wazery Twitter: wazery_ http://stackexchange.com/users/flair/98894.png

Updated on April 09, 2020

Comments

  • Wazery
    Wazery about 4 years

    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.

  • Wazery
    Wazery over 11 years
    Can I specify a certain committer and how to extract this diff to a txt file.
  • jolivier
    jolivier over 11 years
    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
  • Wazery
    Wazery over 11 years
    I mean to extract only commits added by a certain author in my branch.
  • jolivier
    jolivier over 11 years
    but between which ones do you want to diff? the last one?
  • Wazery
    Wazery over 11 years
    I need a diff for a certain author commits between master and mybranch
  • niklas
    niklas over 7 years
    I get fatal: bad revision 'master..develop_content'
  • Karl Henselin
    Karl Henselin about 5 years
    Make sure that you have the branches checked out locally if you get that error.
  • Florian Wendelborn
    Florian Wendelborn about 4 years
    Alternatively, git fetch and git diff master..origin/develop_content
  • Shashank Bhatt
    Shashank Bhatt over 3 years
    I tried this command but it is not showing all differences. Only new file is shown.
  • jolivier
    jolivier over 3 years
    @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.
  • Admin
    Admin almost 2 years
    You now need to add two hyphens to separate the branches from the path: git diff master..yourbranch -- path/to/folder