How can I delete a file from a Git repository?

后端 未结 24 2241
無奈伤痛
無奈伤痛 2020-11-22 13:41

I have added a file named \"file1.txt\" to a Git repository. After that, I committed it, added a couple of directories called dir1 and dir2

24条回答
  •  自闭症患者
    2020-11-22 14:07

    This is the only option that worked for me.

    git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch *.sql'
    

    Note: Replace *.sql with your file name or file type. Be very careful because this will go through every commit and rip this file type out.

    EDIT: pay attention - after this command you will not be able to push or pull - you will see the reject of 'unrelated history' you can use 'git push --force -u origin master' to push or pull

提交回复
热议问题