Skip to content

Instantly share code, notes, and snippets.

@revathskumar
Created March 13, 2012 13:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save revathskumar/2028858 to your computer and use it in GitHub Desktop.
Save revathskumar/2028858 to your computer and use it in GitHub Desktop.
Copy all chaged files with directory structure
./git-copy.sh aabb37fc243675de1194e38f75a554695ed3c111 7b6efc6a0731d0da7ce0d13b19098db2f7da224b ../uploads
#!/bin/bash
# Target directory
TARGET=$3
echo "Coping to $TARGET"
for i in $(git diff --name-only $1 $2)
do
# First create the target directory, if it doesn't exist.
mkdir -p "$TARGET/$(dirname $i)"
# Then copy over the file.
cp "$i" "$TARGET/$i"
done
echo "Done";
@revathskumar
Copy link
Author

How to use

  • save this file to project root folder
  • execute
./git-copy.sh "hash of first commit" "hash of second commit" "destination folder"

@Mgldvd
Copy link

Mgldvd commented Nov 12, 2014

Nice script and very simple, i almost burn my brain doing the same but using a most complicated approach xD.

Here is how i dit:

https://github.com/Mayccoll/Git/tree/master/Git-Zip

In my script you only select one commit, the reason for that is because you always copy the last version of the file, so if you select commits from the middle you are not reflecting the state of the files at that moment.

Maybe i will use your approach for my script :)

Tnks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment