Created
August 15, 2022 11:35
-
-
Save mnemnion/87b51dc8f15af3242204472391f3bf59 to your computer and use it in GitHub Desktop.
Move files from one git repo to another, following renames
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 | |
# 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