Search code examples
gitgit-diff

Git difference between 2 branches show changes made in feature branch only


How can I get git difference of my feature branch w.r.t master branch. I only want changes that are there in the feature branch and exclude changes of master branch. E.g.If feature branch has following commits:

  • b
  • c
  • e
  • f

Whereas master has following commits:

  • a
  • d
  • e
  • f

Then I want all directory names that were modified in just the commit b & c (don't need commit hash just the directory names). I have so far tried git --name-only diff master..feature command but it seems it is returning all the changes.


Solution

  • @Mark's answer really helped me find what I was looking for, thanks a lot for that. But with local branch names I was also getting a lot of entries including the .gitignore which did not have any changes. What worked for me is following, which is a slight modification of Mark's original answer:

    git diff --name-only $(git merge-base remotes/origin/master remotes/origin/feature) remotes/origin/feature
    

    This gave me exactly what I was looking for.