Skip to content

Instantly share code, notes, and snippets.

@patrickmmartin
Last active May 8, 2017 22:37
Show Gist options
  • Save patrickmmartin/48b16912bb7a55645498b7b0a8755f7a to your computer and use it in GitHub Desktop.
Save patrickmmartin/48b16912bb7a55645498b7b0a8755f7a to your computer and use it in GitHub Desktop.
filter-index notes
git filter-branch --index-filter \
        'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
                GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                        git update-index --index-info &&
         mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD

git ls-files -s - lists staged files

GIT_INDEX_FILE - WTF is this? GIT_INDEX_FILE.new seems to be an output variable

git update-index - --index-info Read index information from stdin. supports git ls-files -s

from http://jeffreysambells.com/2010/09/13/a-little-bit-of-git-fu

git filter-branch --index-filter 'git ls-files -s | sed "s-\t-&newdir/-" |
    GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
    git update-index --index-info &&
    if test -f "$GIT_INDEX_FILE.new"; then mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE; fi' HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment