从远程 Git 存储库中删除所有文件和历史记录而不删除存储库本身
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5363857/
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
Delete all files and history from remote Git repo without deleting repo itself
提问by max_
I would appreciate it if someone could tell me how I could delete every single file/folder on my git repository without actually deleting the repository itself. I want to delete all history associated with those files as well.
如果有人能告诉我如何删除 git 存储库中的每个文件/文件夹而不实际删除存储库本身,我将不胜感激。我也想删除与这些文件相关的所有历史记录。
采纳答案by Ceilingfish
You can delete a branch from a repository remote like this
您可以像这样从远程存储库中删除分支
git push origin :branchname
if you've got any tags you can delete them like this:
如果你有任何标签,你可以像这样删除它们:
git push origin :refs/tags/tagname
This is assuming you have a remote set up to github called origin
这是假设你有一个远程设置到 github 叫做 origin
This will leave the local tags / branches on your computer, though.
不过,这会将本地标签/分支留在您的计算机上。
回答by
As I explain in this answerto Delete or remove all history, commits, and branches from a remote Git repo?, you can also achieve the same thing as Ceilingfish's answer(i.e. delete all references/branches/tags in the remote repo) by doing the following:
正如我在这个关于从远程 Git 存储库删除或删除所有历史记录、提交和分支的答案中所解释的那样?,您还可以通过执行以下操作来实现与Ceilingfish 的回答相同的事情(即删除远程存储库中的所有引用/分支/标签):
Create new empty repo with initial commit:
mkdir new cd new echo "This is the README" > README.md git init git add . git commit -m "Add README.md (initial commit)"
Add remote repo as origin:
git remote add origin <url-to-remote>
Mirror push to remote:
git push origin --mirror
使用初始提交创建新的空仓库:
mkdir new cd new echo "This is the README" > README.md git init git add . git commit -m "Add README.md (initial commit)"
添加远程仓库作为原点:
git remote add origin <url-to-remote>
镜像推送到远程:
git push origin --mirror
That will delete all references/branches/tags in your remote repo, and any dangling commits will probably be garbage collected eventually. From the official Linux Kernel Git documentation for git push
(emphasis mine):
这将删除远程 repo 中的所有引用/分支/标签,并且任何悬而未决的提交最终可能会被垃圾收集。来自官方 Linux 内核 Git 文档git push
(重点是我的):
--mirror
Instead of naming each ref to push, specifies that all refs under
refs/
(which includes but is not limited torefs/heads/
,refs/remotes/
, andrefs/tags/
) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end.
--mirror
代替命名每个裁判推的,则指定下的所有参考文献
refs/
(包括但不限于refs/heads/
,refs/remotes/
和refs/tags/
)被镜像到远程存储库。新创建的本地 refs 将被推送到远程端,本地更新的 refs 将在远程端强制更新,删除的 refs 将从远程端删除。
回答by Christophe
This is what I have done
这就是我所做的
git rm -r -f -q
git commit
git push
git rm -r -f -q
提交
推
Then you have to manually delete the files, git rm remove the files from the repo but not from the file system
然后你必须手动删除文件, git rm 从 repo 中删除文件而不是从文件系统中删除