Skip to content

Instantly share code, notes, and snippets.

@robertwtucker
Created January 27, 2022 07:14
Show Gist options
  • Save robertwtucker/629a20a0664ad6ce87adbe2cc81e5dd6 to your computer and use it in GitHub Desktop.
Save robertwtucker/629a20a0664ad6ce87adbe2cc81e5dd6 to your computer and use it in GitHub Desktop.
Move Git Files with History Preservation
mkdir ~/dirswap && cd ~/dirswap
git clone repo1.git && cd repo1
# My use case: repo1/chart -> repo2/appname (mv < migration)
mv chart appname
git commit -am "chore: migrating helm chart to charts repo"
git filter-repo --path-rename chart/:appname/ --force
mkdir /tmp/mergepatches
export REPOSRC=appname # (or srcfile.go if moving a file)
git format-patch -o /tmp/mergepatches $(git log $REPOSRC|grep ^commit|tail -1|awk '{print $2}')^..HEAD $REPOSRC
cd ~/dirswap
git clone repo2.git && cd repo2
git am /tmp/mergepatches/*.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment