2

I have a branch named feature_219 which was created from master a little while ago. Since the diversion, there were a number of files changed on both the branches.

Now I am trying to figure out what files where changed while working on the feature_219 branch only.

After doing some research I found out that git diff --name-only master feature_219 might help but it turned out that this commands tells about all files that are different in both the branches. I tried to look for some option with this command but nothing worked for me.

Is there any way to list only those files that were changed in feature_219 branch?

Kashif Nazar
  • 20,775
  • 5
  • 29
  • 46
  • 2
    Your question is unclear. "Different" compared to what? To the merge base of `feature_219` and `master`? Be more specific. Whenever you use the word "different", specify also what you're comparing to. – jub0bs Apr 17 '15 at 15:00
  • 2
    *Is there any way to list only those files that were changed in feature_219 branch?* Changed with respect to what? – jub0bs Apr 17 '15 at 15:16

2 Answers2

5

According to the git diff documentation

git diff --name-only master...feature_219

should do the trick. Notice the three dots. If you're currently on branch feature_219

git diff --name-only master...

suffices. The order of the two branches is very important. Interchanging the two branches in the first call will give you all changes in the master branch since you started the feature_219 branch.

The command git diff A...B should be interpreted as "give me all changes which happen in the commits when going from A to B". If A is not a parent of B (as in this case) the common ancestor will be used to answer this question.

Nils_M
  • 1,062
  • 10
  • 24
3

You could use git merge-base to find a common ancestor of two branches, then get the diff.

git diff --name-only feature_219 $(git merge-base master feature_219)
xdazz
  • 158,678
  • 38
  • 247
  • 274