I am trying to figure out how to get files from a Git repository that were modified in a given commit. I would like to store the 'delta' in a separate folder. I'm quite new to Git, so this might be relatively basic question, but still..
I thought I should first get the repository at the version:
git reset --hard a02ea0d
Then list the content of the commit:
git show --pretty="" --name-only a02ea0d
But then what? Can I plumb this together to have some extra folder as a result just with the actual files at the version?
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\'
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.
The environment used in this example is a machine running Windows 10 using Git Bash.
git init
within a certain folderabc
cba
git add
all files afterwards git commit
themabcabc
cbacba
git add
all files afterwards git commit
themgit log
and find the SHA1 for the first and the second commitThe folder specified in the command will now contain all the files that changed between the two provided commits looking like this.
abc
cba
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With