How to remove a folder from a repository in github?

一世执手 提交于 2021-02-08 08:46:42

问题


I want to remove a folder from a repository in GitHub, i have pushed it as an attempt to try some git commands, but now i can't delete it, i tried with git rm -r --cached folder name and git tells me that it doesn't match any file. my objective is to keep the local folder and deleting it only from git. Thanks for help!


回答1:


Please perform following steps:

  1. In your local machine, move folder to anywhere outside this repository for backup.
  2. git add .
  3. git commit with proper message
  4. git push origin <your branch>
  5. Move folder from backed up location to this repository again

In future, to avoid push of this folder in remote git, you should add entry for this folder in .gitignore file.




回答2:


  1. Cut the folder
  2. Move to other directories
  3. git add .
  4. git commit -m "Removing directories"
  5. git push origin your-branch
  6. Move it back.

I think it sounds crazy but since you want to do it, why wouldn't to try it?




回答3:


Note: since January 2021, you can also delete that folder directly on GitHub.

Delete directory from the web

You can now delete an entire directory of files including subdirectories from your web browser:

  • Browse to the directory in the repository and branch that you want to delete
  • In the top-right corner, click "", and then Delete directory
  • Review the list of files
  • Depending on your permissions and the branch protection rules, choose to either commit the change directly or propose the change using a pull request

Learn more about deleting a file or directory.

Then you can fetch, and then restore/update your local branch, without deleting the (now) deleted remote files

git fetch
git read-tree origin/main
git checkout-index -f -a
git update-index -q --refresh


来源:https://stackoverflow.com/questions/53610000/how-to-remove-a-folder-from-a-repository-in-github

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!