How can I delete a file from a Git repository?

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

    First, if you are using git rm, especially for multiple files, consider any wildcard will be resolved by the shell, not by the git command.

    git rm -- *.anExtension
    git commit -m "remove multiple files"
    

    But, if your file is already on GitHub, you can (since July 2013) directly delete it from the web GUI!

    Simply view any file in your repository, click the trash can icon at the top, and commit the removal just like any other web-based edit.

    Then "git pull" on your local repo, and that will delete the file locally too.
    Which makes this answer a (roundabout) way to delete a file from git repo?
    (Not to mention that a file on GitHub is in a "git repo")


    (the commit will reflect the deletion of that file):

    commit a deletion

    And just like that, it’s gone.

    For help with these features, be sure to read our help articles on creating, moving, renaming, and deleting files.

    Note: Since it’s a version control system, Git always has your back if you need to recover the file later.

    The last sentence means that the deleted file is still part of the history, and you can restore it easily enough (but not yet through the GitHub web interface):

    See "Restore a deleted file in a Git repo".

提交回复
热议问题