Git - 如何从远程存储库中删除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9701238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git - how delete file from remote repository
提问by paganotti
How can I delete file from remote git repository? I have a file that is just deleted from working copy local repository, and I want delete it from corresponding remote repository
如何从远程 git 存储库中删除文件?我有一个刚刚从工作副本本地存储库中删除的文件,我想从相应的远程存储库中删除它
回答by jabal
If you deleted a file from the working tree, then commit the deletion:
如果您从工作树中删除了一个文件,则提交删除:
git commit -a -m "A file was deleted"
And push your commit upstream:
并将您的提交推送到上游:
git push
回答by Mayank Raipure
Use commands :
使用命令:
git rm /path to file name /
followed by
其次是
git commit -m "Your Comment"
git push
your files will get deleted from the repository
您的文件将从存储库中删除
回答by zarpio
A simpler way
更简单的方法
git add . -A
git commit -m "Deleted some files..."
git push origin master
-AUpdate the index not only where the working tree has a file matching but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree. Taken from (http://git-scm.com/docs/git-add)
-A不仅在工作树有文件匹配的地方更新索引,而且在索引已经有条目的地方更新索引。这会添加、修改和删除索引条目以匹配工作树。取自(http://git-scm.com/docs/git-add)
回答by ireshika piyumalie
- If you want to push a deleted file to remote
- 如果要将已删除的文件推送到远程
git add 'deleted file name'
git commit -m'message'
git push -u origin branch
git add 'deleted file name'
git commit -m'message'
git push -u origin branch
- If you want to delete a file from remote and locally
- 如果要从远程和本地删除文件
git rm 'file name'
git commit -m'message'
git push -u origin branch
git rm 'file name'
git commit -m'message'
git push -u origin branch
- If you want to delete a file from remote only
- 如果您只想从远程删除文件
git rm --cached 'file name'
git commit -m'message'
git push -u origin branch
git rm --cached 'file name'
git commit -m'message'
git push -u origin branch
回答by Christophe Roussy
If you pushed a file or folder before it was in .gitignore (or had no .gitignore):
如果您在 .gitignore 之前推送文件或文件夹(或没有 .gitignore):
- Comment it out from .gitignore
- Add it back on the filesystem
- Remove it from the folder
- git add your file && commit it
- git push
- 从 .gitignore 中注释掉
- 将其添加回文件系统
- 从文件夹中删除它
- git add 你的文件 && 提交它
- 推
回答by andy boot
if you just commit your deleted file and push. It should then be removed from the remote repo.
如果您只是提交已删除的文件并推送。然后应该从远程仓库中删除它。
回答by Bharat Bhushan
Git Remote repository file deletion simple solution:
Git远程仓库文件删除简单解决办法:
git commit (file name with path which you want to delete) -m "file is deleted"
git push
git commit (要删除的路径的文件名) -m "文件已删除"
推
It will work.Multiple selective file also you can delete in remote repository same way.
它会工作。多个选择性文件也可以在远程存储库中以相同的方式删除。
回答by Armen Arzumanyan
If you have deleted lot of files and folders, just do this
如果您删除了大量文件和文件夹,请执行以下操作
git commit -a -m .
git push
回答by vii
Visual Studio Code:
视觉工作室代码:
Delete the files from your Explorer view. You see them crossed-out in your Branch view. Then commit and Sync.
从资源管理器视图中删除文件。您会在Branch 视图中看到它们被划掉。然后提交和同步。
Be aware:If files are on your .gitignore list, then the delete "update" will not be pushed and therefore not be visible. VS Code will warn you if this is the case, though. -> Exclude the files/folder from gitignore temporarily.
请注意:如果文件在您的 .gitignore 列表中,则不会推送删除“更新”,因此不可见。但是,如果是这种情况,VS Code 会警告您。-> 暂时从 gitignore 中排除文件/文件夹。