Last active
October 8, 2018 05:33
-
-
Save JonWallsten/b2ab927a7d90809fbdc79e636cb52913 to your computer and use it in GitHub Desktop.
Move/rename any file and keep git commit history
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
# Move/rename any file and keep git history | |
git filter-branch --index-filter 'git ls-files -s | sed "s|[old_path]|[new_path]|g" | | |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \ | |
git update-index --index-info && | |
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' [first_commit_hash]..HEAD | |
# Example | |
git filter-branch --index-filter 'git ls-files -s | sed "s|packages/web-app|packages/web-app-new|g" | | |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \ | |
git update-index --index-info && | |
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' fceab398..HEAD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment