Skip to content

Instantly share code, notes, and snippets.

@JonWallsten
Last active October 8, 2018 05:33
Show Gist options
  • Save JonWallsten/b2ab927a7d90809fbdc79e636cb52913 to your computer and use it in GitHub Desktop.
Save JonWallsten/b2ab927a7d90809fbdc79e636cb52913 to your computer and use it in GitHub Desktop.
Move/rename any file and keep git commit history
# 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