Reputation: 1563
How can I export all files that were changed in the last commit ?
Can I get only the list of last committed files is separate folder ?
Upvotes: 5
Views: 4992
Reputation: 494
Create a file with name git-copy.sh with the following content:
#!/bin/bash
# Target directory
TARGET=$3
echo "Finding and copying files and folders 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 "Files copied to target directory";
Run the script as a command from the root of your git project:
./git-copy.sh git-hash-1 git-hash-2 path/to/destination/folder
It will copy all the files with same directory structure to the destination folder.
Upvotes: 15
Reputation: 4564
Here is a small bash(Unix) script that I wrote that will copy files for a given commit hash with the folder structure:
ARRAY=($(git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $1))
PWD=$(pwd)
if [ -d "$2" ]; then
for i in "${ARRAY[@]}"
do
:
cp --parents "$PWD/$i" $2
done
else
echo "Chosen destination folder does not exist."
fi
Create a file named '~/Scripts/copy-commit.sh' then give it execution privileges:
chmod a+x ~/Scripts/copy-commit.sh
Then, from the root of the git repository:
~/Scripts/copy-commit.sh COMMIT_KEY ~/Existing/Destination/Folder/
To get the last commit hash:
git rev-parse HEAD
Upvotes: 3