Export files from a revision or range of revisions with Git
If there is one thing I miss about using TortoiseSVN was the convinence of exporting a group of files from a revision or range of revisions. Currently I know of no way of doing this in Git, so I decided to roll my own Git alias to accomplish this.
The alias below takes two arguments:
- the revision or range of revision you want to export files from
- the directory you want to place them in
So if you want to export all the changed files from HEAD to HEAD~2 and put them in the /cygdrive/c/temp directory, you would do:
$ git exportfiles HEAD..HEAD~2 '/cygdrive/c/temp'
The code is below:
exportfiles = !sh -c 'git diff $0 --name-only | "while read files; do mkdir -p \"$1/$(dirname $files)\"; cp -vf $files $1/$(dirname $files); done"'
Just cut and paste it into the [alias] portion of you .git/config file and you’re ready to go.
As always, if you have a better solution, please leave it in the comments below.