29

I use a Git repository on my server to version user data files sent to the server. I'm interested in getting a list of changed files between any two revisions.

I know about git diff --name-only <rev1> <rev2>, but this only gives me a list of file names. I'm especially interested in renames and copies, too. Ideally, the output would be something like this:

updated:  userData.txt
renamed:  picture.jpg -> background.jpg
copied:   song.mp3 -> song.mp3.bkp

Is it possible? --name-status also doesn't seem to indicate renames and copies.

Jean-Philippe Pellet
  • 59,296
  • 21
  • 173
  • 234

2 Answers2

33
git diff --name-status -C <rev1> <rev2>

should be closer to what you are looking for.

--name-status would display the file names and their respective status:

(A|C|D|M|R|T|U|X|B)

Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R),
type (i.e. regular file, symlink, submodule, …) changed (T),
Unmerged (U), Unknown (X), or pairing Broken (B)

(to which the OP Jean Philippe Pellet adds:

The status letters R and C “are always followed by a score denoting the percentage of similarity between the source and target of the move or copy, and are the only ones to be so". )

Regarding files copied or moved:

-C[<n>]
--find-copies[=<n>]

Detect copies as well as renames. If n is specified, it has the same meaning as for -M<n>.

--find-copies-harder

For performance reasons, by default, -C option finds copies only if the original file of the copy was modified in the same changeset.
This flag makes the command inspect unmodified files as candidates for the source of copy.
This is a very expensive operation for large projects, so use it with caution. Giving more than one -C option has the same effect.


brauliobo recommends in the comments:

git diff --stat -C
git show --stat -C
git log --stat -C
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Great, this is exactly what I need. For completeness sake, I'll add that the status letters `R` and `C` “are always followed by a score denoting the percentage of similarity between the source and target of the move or copy, and are the only ones to be so” ([source](http://www.kernel.org/pub/software/scm/git/docs/git-diff.html)). – Jean-Philippe Pellet May 19 '11 at 11:59
  • @Jean-Philippe: good point. I have included it in the answer. – VonC May 19 '11 at 12:33
  • Thanks! The only part left open is how to interpret entries with type `X` or `B`… – Jean-Philippe Pellet May 19 '11 at 12:41
  • @Jean-Philippe: true, hopefully you won't have to parse that kind of entry that often ;) – VonC May 19 '11 at 12:47
  • I've asked a follow-up question [there](http://stackoverflow.com/questions/6058879/what-do-the-git-pairing-broken-and-unknown-statuses-mean-and-when-do-they-oc) about `X` and `B`. – Jean-Philippe Pellet May 19 '11 at 12:52
  • @brauliobo not sure -`-C` and `--name-status` are supported by `git show` as well), but you can ask an independent question. – VonC Nov 05 '15 at 16:20
  • @Vonc `-C --stat` is the answer for `diff`, `show` and `log` – brauliobo Nov 05 '15 at 16:21
  • @brauliobo true, those options are supported by all three commands. – VonC Nov 05 '15 at 16:22
3

I believe `` will show that information

git diff -M -C --stat
sehe
  • 374,641
  • 47
  • 450
  • 633