4

Very similar question as this one: Export only modified and added files with folder structure in Git

The given answer only seems to output the files changed in the given commit ($commit_id):

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit_id

I'd like to get the list of modified files between commit1 and commit2... Is this possible?

Community
  • 1
  • 1
Trev
  • 1,358
  • 3
  • 16
  • 28

2 Answers2

8

You should just be able to use the commit IDs. For example:

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT 218d182e 3ef44d29d

If you want to include the changes in commit 3ef44d29d then you need to specify its parent either by ID or with 3ef44d29d^.

Here are some examples, from one of my own projects. Going backwards in history, I have the following commits:

1a443
fb4ae
88226
c46ba

I get the following output from various commands:

$ git diff-tree -r --name-only 1a443
1a443831fa9f797fedb397e900bd3d45e2093ea6
public/customers.en.html
$ git diff-tree -r --name-only fb4ae
fb4ae4af0ac473b8547ec1717d4b4172c0d634f4
public/checkout.en.html
$ git diff-tree -r --name-only 88226
88226fec6f1082b1dffd266d3e1bd0dc38cca520
public/finish.en.html
$ git diff-tree -r --name-only c46bac
c46bacddee7785599c2f026f53cd93357e8ad30d
public/index.php

I can get all the changes between c46bac and 1a443 easily enough:

$ git diff-tree -r --name-only c46bac 1a443
public/checkout.en.html
public/customers.en.html
public/finish.en.html

But notice that it doesn't include the change to public/index.php in commit c46bac. What we really want is to use the parent of that commit as our starting point for comparison.

$ git diff-tree -r --name-only c46bac^ 1a443
public/checkout.en.html
public/customers.en.html
public/finish.en.html
public/index.php
slashingweapon
  • 11,007
  • 4
  • 31
  • 50
  • It looks like it only returns the files from the most recent commit, no matter what order they're in in the command – Trev Nov 01 '12 at 16:54
  • How far apart are your two commits? If one is simply the parent of the other, then you're getting exactly the right answer. But if the two are more far apart than that ... I'll experiment some. – slashingweapon Nov 01 '12 at 17:33
  • They're right beside each other. And I verified that I get a different list of files when I use each commit id by itself. – Trev Nov 01 '12 at 17:47
  • 1
    Use the `^` character at the end of your earlier commit to indicate you want to use its parent. – slashingweapon Nov 01 '12 at 17:53
0

git diff --name-only commit1..commit2

Nicolas Dermine
  • 628
  • 5
  • 8