Skip to content

Instantly share code, notes, and snippets.

@andruhon
Created January 6, 2016 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andruhon/ba3da3ba700fe75943cb to your computer and use it in GitHub Desktop.
Save andruhon/ba3da3ba700fe75943cb to your computer and use it in GitHub Desktop.
Windows CMD one-line command to copy difference of two GIT commits into specific directory preserving directories hierarchy:
git diff --name-only yrc0m1 yrc0m2|sed s:/:\\:g > report.txt && for /F %F in ('cat report.txt') do xcopy %F c:\m1m2diff\%F && del report.txt
#*xcopy will ask you to confirm wither the path is file or directory for each of your changed files. As far as diff returns only files changed, you can just do long F button press :-) Unfortunately I did not succeed to find a flag to suppress this warning with F option.
#It consists of following subcommands:
#1. git diff --name-only yrc0m1 yrc0m2 - returns list of changed files between commits yrc0m1 and yrc0m2;
#2. sed s:/:\\:g - piped with | after previous one, converting Linux slashes to windows slashes;
#3. > report.txt - oputput of previous two commands: all relative filepaths are saved in report.txt;
#4. for /F %F in ('cat report.txt') do xcopy %F c:\m1m2diff\%F - iterates through lines in report.txt and copying file creating all not-existing directories from it's relative path (we suppose that c:\m1m2diff\ directory already exists)
#5. del report.txt - simply deletes report.txt file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment