Skip to content

Instantly share code, notes, and snippets.

@hatzopoulos
Last active August 29, 2015 14:26
Show Gist options
  • Save hatzopoulos/04b3a16b1035915b946a to your computer and use it in GitHub Desktop.
Save hatzopoulos/04b3a16b1035915b946a to your computer and use it in GitHub Desktop.
git-filter-branch new root directory
git filter-branch --prune-empty --tree-filter '
if [[ ! -e httpdocs ]]; then
    mkdir -p httpdocs
    git ls-tree --name-only $GIT_COMMIT | xargs -I files mv files httpdocs
fi'

# this doesn't work because of the single quotes in single quotes
git filter-branch --prune-empty --tree-filter '
if [[ ! -e httpdocs ]]; then
    mkdir -p httpdocs
    git ls-tree --name-only $GIT_COMMIT | grep -v ^'.gitignore\|.gitattributes'$ | xargs -I files mv files httpdocs
fi'
#!/bin/bash
# usage:
# cd ~/your-repo
# git filter-branch --prune-empty --tree-filter ~/rewrite-history.bash
if [[ ! -e httpdocs ]]; then
mkdir -p httpdocs
git ls-tree --name-only $GIT_COMMIT | grep -v ^'.gitignore\|.gitattributes'$ | xargs -I files mv files httpdocs
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment