How can I delete a file from a Git repository?

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

    I have obj and bin files that accidentally made it into the repo that I don't want polluting my 'changed files' list

    After I noticed they went to the remote, I ignored them by adding this to .gitignore

    /*/obj
    /*/bin
    

    Problem is they are already in the remote, and when they get changed, they pop up as changed and pollute the changed file list.

    To stop seeing them, you need to delete the whole folder from the remote repository.

    In a command prompt:

    1. CD to the repo folder (i.e. C:\repos\MyRepo)
    2. I want to delete SSIS\obj. It seems you can only delete at the top level, so you now need to CD into SSIS: (i.e. C:\repos\MyRepo\SSIS)
    3. Now type the magic incantation git rm -r -f obj
      • rm=remove
      • -r = recursively remove
      • -f = means force, cause you really mean it
      • obj is the folder
    4. Now run git commit -m "remove obj folder"

    I got an alarming message saying 13 files changed 315222 deletions

    Then because I didn't want to have to look up the CMD line, I went into Visual Sstudio and did a Sync to apply it to the remote

提交回复
热议问题