Skip to content

Instantly share code, notes, and snippets.

@mnemnion
Created August 15, 2022 11:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mnemnion/87b51dc8f15af3242204472391f3bf59 to your computer and use it in GitHub Desktop.
Save mnemnion/87b51dc8f15af3242204472391f3bf59 to your computer and use it in GitHub Desktop.
Move files from one git repo to another, following renames
#! /bin/bash
# Usage:
# ./git-move.sh path1/ path2/... path/to/destination/repo
args=("$@")
# All but last argument:
paths=("${args[@]::${#args[@]}-1}")
# Last argument:
dest="${args[${#args[@]}-1]}"
echo "creating patch for paths: ${paths[@]}"
echo "moving to destination: $dest"
# Iterate path arguments and append to tmpfile:
for p in "${paths[@]}"
do
git log --name-only --pretty="format:" --follow -- "$p" >> __LOGNAMES_TMP1290
done
cat __LOGNAMES_TMP1290
cat __LOGNAMES_TMP1290 | sort -u | \
xargs git log --pretty=email --patch-with-stat --reverse --full-index --binary -m --first-parent -- > "$dest/_patch_"
trash __LOGNAMES_TMP1290
echo "moving to destination repo at $dest"
cd "$dest"
echo "applying patch"
git am -s --committer-date-is-author-date < _patch_
#trash _patch_
echo "OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment