Solution
git checkout <SHA of old commit>
git diff --name-only <SHA of old commit> <SHA of newer commit> | xargs git checkout-index -f --prefix='C:\changes\'
Explanation
git checkout <SHA of old commit>
will cause the following git checkout-index
to copy files out of the old commit.
git diff --name-only <SHA of old commit> <SHA of newer commit>
will return a list of all files that have been changed between the old and the newer commit.
xargs git checkout-index -f --prefix='C:\changes\'
will take all the files returned by the first command (by using a pipe) and will use each line as an argument for the following git checkout-index
command.
Example
The environment used in this example is a machine running Windows 10 using Git Bash.
git init
within a certain folder
- Creat two files
- file1.txt containing
abc
- file2.txt containing
cba
git add
all files afterwards git commit
them
- Change file1.txt and file2.txt
- file1.txt containing
abcabc
- file2.txt containing
cbacba
git add
all files afterwards git commit
them
git log
and find the SHA1 for the first and the second commit
- Apply the solution I offered above
The folder specified in the command will now contain all the files that changed between the two provided commits looking like this.
- file1.txt contains
abc
- file2.txt contains
cba