Skip to content

Instantly share code, notes, and snippets.

@alvis
Last active March 22, 2020 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvis/5398f9f81db7130cbfd7e26b3b210da8 to your computer and use it in GitHub Desktop.
Save alvis/5398f9f81db7130cbfd7e26b3b210da8 to your computer and use it in GitHub Desktop.
git: move a folder with all histories rewritten
#!/bin/sh
FROM=$1
TO=$2
TEMP=$(mktemp -d)
echo Moving "$FROM" to "$TO"
git filter-branch -f --tree-filter "if [[ -e '$FROM' ]]; then mkdir -p "$(dirname $TO)"; mv '$FROM/' '$TEMP'; mv '$TEMP/' '$TO/'; fi" --tag-name-filter cat --prune-empty -- --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment