Created
April 25, 2020 17:43
-
-
Save cppio/1fb6c9785a1e6c08395432205ce1bce5 to your computer and use it in GitHub Desktop.
A simple script to get specific files from a git repo without cloning the whole thing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| shopt -s dotglob nullglob | |
| dest="$(pwd)" | |
| tempdir="$(mktemp -d)" | |
| git clone --depth 1 --no-checkout --filter=blob:none "${1%%@*}" "$tempdir" | |
| tag="$(tag=${1#*@}; repo="${1##*@*}"; repo="${repo:+HEAD}"; echo "${repo:-$tag}")" | |
| shift | |
| cd "$tempdir" | |
| git checkout "$tag" -- "$@" | |
| rm -rf .git | |
| mv * "$dest" 2>&- | |
| rm -rf "$tempdir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment