Created
January 27, 2022 07:14
-
-
Save robertwtucker/629a20a0664ad6ce87adbe2cc81e5dd6 to your computer and use it in GitHub Desktop.
Move Git Files with History Preservation
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
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