Created
April 29, 2020 16:38
-
-
Save dvdveer/a47966db83af115e6200124f92e22761 to your computer and use it in GitHub Desktop.
Shell script to create a git bundle including changed LFS files
This file contains 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/sh | |
# This script creates a bundle of git commits between START and END. | |
# It also tars the lfs files that changed in those commits. | |
# When you unbundle on the receiving side you should untar the LFS tar *before* | |
# running 'git pull' on the bundle file. | |
# Note that this is just an example script that doesn't do error checking, and | |
# also doesn't account for submodules, etc. YMMV | |
# Start and end commits of bundle | |
START="master~50" | |
END="master" | |
# Normal git bundle file | |
BUNDLE_FILE="mybundle.bundle" | |
# Tar file with required lfs files | |
LFS_FILE="mybundle_lfs.tar" | |
# Create normal git bundle between START and END commits | |
git bundle create ${BUNDLE_FILE} ${START}..${END} -- | |
# Create tmp file with list of lfs files to put in tar | |
FILES_LIST=`mktemp` | |
# Path where lfs objects are stored | |
lfsobjpath=".git/lfs/objects" | |
# ls-files returns LFS files changed between START and END commit. We then convert hashes to file paths in .git/lfs/objects directory | |
git lfs ls-files --long ${START} ${END} | awk '{ print $1 }' | sed -r 's_^([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]+)_'$lfsobjpath'/\1/\2/\1\2\3_' >> $FILES_LIST | |
# Create tar archive with lfs files | |
tar --files-from=$FILES_LIST -cf ${LFS_FILE} | |
# Remove temporary file | |
rm $FILES_LIST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment