How can I delete a file from a Git repository?

后端 未结 24 2252
無奈伤痛
無奈伤痛 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:06

    The answer by Greg Hewgill, that was edited by Johannchopin helped me, as I did not care about removing the file from the history completely. In my case, it was a directory, so the only change I did was using:

    git rm -r --cached myDirectoryName
    

    instead of "git rm --cached file1.txt" ..followed by:

    git commit -m "deleted myDirectoryName from git"
    git push origin branch_name
    

    Thanks Greg Hewgill and Johannchopin!

提交回复
热议问题