15w-vw
Last Updated: February 25, 2016
·
457
· jakebellacera
59fc45b9f32d3072f37f8471d4968453

git diff

If you ever need to get a list of files changed between two commits in git, you can accomplish this by using git diff.

git diff --name-only A..B

A is the start of your range and B is the end of your range. Note the two dots between the two endpoints! They're important. A and B can be any sort of reference: a commit SHA (i.e. a12e34o13), a branch (i.e. HEAD), or even a tag (i.e. v2.0.0).

I frequently use this with tags. It gives me a great way to produce a list of files between two versions. For example:

$ git diff --name-only v2.0.0..v3.0.0

css/styles.css
css/normalize.css
js/script.js
img/background.jpg
img/logo.jpg
index.html

Isn't that nice?

Bonus: piping with cpio

cpio is an excellent utility that lets you essentilly perform a copy that maintains a file structure. I use cpio all the time in conjuction with git diff's output to produce a folder that contains a patch. Here's how I do it:

git diff --name-only v2.0.0..v3.0.0 | cpio -pdum v3.0.0-patch

I will now have a folder containing the list of files produced from git diff!


If you liked this, please consider following me on Twitter.

Say Thanks
Respond