Remove deleted files from git history

后端 未结 2 1885
礼貌的吻别
礼貌的吻别 2020-12-04 19:26

I\'m trying to split a subproject off of my git repository. However unlike in Detach (move) subdirectory into separate Git repository I don\'t have it in it\'s own subdirect

相关标签:
2条回答
  • 2020-12-04 20:19

    Ok now I'm trying with the following technique, will report back if it worked, because it seems to be quite long running: On a zsh or bash ON A CLONED Repository

    git log --diff-filter=D --summary <start_commit>..HEAD | egrep -o '*[[:alnum:]]*(/[[:alnum:].]*)+$' > deleted.txt
    

    to get all deleted files

    for del in `cat deleted.txt`
    do
        git filter-branch --index-filter "git rm --cached --ignore-unmatch $del" --prune-empty -- --all
        # The following seems to be necessary every time
        # because otherwise git won't overwrite refs/original
        git reset --hard
        git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
        git reflog expire --expire=now --all
        git gc --aggressive --prune=now
    done;
    

    This might be extremly dangeours for your data so only try on clones.

    0 讨论(0)
  • 2020-12-04 20:20

    Here are some instructions to do what you want.

    This will remove file_to_remove:

    git filter-branch --index-filter 'git rm --cached --ignore-unmatch file_to_remove' --prune-empty -- --all
    
    0 讨论(0)
提交回复
热议问题