23

I apolagise if this isn't very clear but in Git, is there a way to see all changed files on a branch, by name only. As far as I know I can use git log to see files that have changed in a single commit but I want to see all files that have changed since the branch was created, over several commits.

There is git diff but this also lists the changed files in the branch I'm comparing to which I don't want to see. I kind of want a command that says 'show me file names for all changed files in this branch'.

Many thanks

screenm0nkey
  • 16,975
  • 17
  • 53
  • 75

4 Answers4

53

Supposing you're on branch foo, and you're interested in which files have changed since the point when it diverged from master, you can just do:

git diff --name-only master...

(Note the three dots.) If you're not foo, you can use the full form:

git diff --name-only master...foo

I made some graphics that explain the double-dot and triple-dot notations, and their differences between their meaning in git rev-list and git log - you can find them in this answer.

Community
  • 1
  • 1
Mark Longair
  • 385,867
  • 66
  • 394
  • 320
  • Also worth noting that if you reverse the order branch names in the latter argument you can check for changes on the original branch (great for giving an indication of changes there before a merge) – stephenfin Oct 03 '13 at 09:48
2

Don't know that there is something that does exactly what you want based only on your current branch, but if you know the commit id that is the parent of your branch, you can do:

git diff --name-only <commit id of branch point>..HEAD
antlersoft
  • 14,223
  • 3
  • 28
  • 52
  • that is a good idea and one i thought about but I don't know how to work out which commit to compare to on the master when I created the branch. did that make sense? – screenm0nkey Aug 02 '11 at 14:17
  • 1
    You can use the triple-dot notation (e.g. `git diff A...B`) in order to compare between the merge base of `A` and `B` (which in most cases will be the branch point you're talking about) and `B`. I've added a bit more about that in my answer. – Mark Longair Aug 02 '11 at 14:24
  • What is the simplest way to determine the commit id of the branching point? Many of the examples assume it is master but it may not be if you've branched from another feature branch. – u01jmg3 Sep 12 '19 at 09:34
1

Assuming you have checked out the branch you are working on, and you want to compare it to master:

git diff --name-only master
nocache
  • 1,695
  • 15
  • 18
  • That does a diff between the tip of master and HEAD - the OP is asking about files that have just changed on the topic branch. – Mark Longair Aug 02 '11 at 14:19
0

I am using this command to find out the list of N files changed between two versions, here N is 50

git log  --pretty=format: --name-only <SourceBranch>...<TargetBranch> | sort | uniq -c | sort -rg | head -50
Pawan Maheshwari
  • 14,070
  • 1
  • 46
  • 48