我可以清空远程 git 存储库吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4120502/
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
can I empty a remote git repository?
提问by Radek
I created new remote git repositoryand already pushed something in there - first test push and then real code push from local. I want to start from scratchso I can creat few branches (master = ready to release code, test branch and branches for developers) and give them different permissions per user.
我创建了新的远程 git 存储库,并且已经在那里推送了一些东西——首先是测试推送,然后是从本地推送真正的代码。我想从头开始,这样我就可以创建几个分支(master = 准备发布代码、测试分支和开发人员分支)并为每个用户赋予不同的权限。
Can I empty the existing remote repositorysomehow? It's a remote git repository that sits on linux and developer and I run windows box.
我可以以某种方式清空现有的远程存储库吗?这是一个远程 git 存储库,位于 linux 和开发人员上,我运行 windows box。
采纳答案by Cascabel
If you want the repo gone, just take it away! Delete the whole containing directory, and recreate it as you see fit.
如果你想让 repo 消失,就把它拿走!删除整个包含目录,然后根据需要重新创建它。
Yes, you could also make a new repo just on your end, and force push to the remote, and remotely delete all the refs, and then make sure git gc
gets run on it... but that takes time and effort. Just wipe it out.
是的,您也可以在自己的一端创建一个新的存储库,然后强制推送到远程,并远程删除所有引用,然后确保git gc
在其上运行……但这需要时间和精力。把它擦掉就行了。
回答by Sven Marnach
I don't think it is very useful, but you can restart the master branch (forgetting all history) by
我认为它不是很有用,但是您可以通过以下方式重新启动 master 分支(忘记所有历史记录)
rm .git/index .git/refs/heads/master
echo "Hello!" > README
git add README
git commit -m "Exterminate! Exterminate!"
and push to your remote repository. Usually I would just start over with an empty repository, add your remote repository and push from there.
并推送到您的远程存储库。通常我会从一个空的存储库重新开始,添加您的远程存储库并从那里推送。
Some explanation: The first line deletes the index (so your next commit won't contain any files) and the current pointer to the tip of the master branch (so your next commit won't be committed on top of any previous commit). In the second and third line, we add some content to our new repository and commit that content in the fourth line.
一些解释:第一行删除索引(因此您的下一次提交将不包含任何文件)和指向主分支尖端的当前指针(因此您的下一次提交不会在任何先前提交之上提交)。在第二行和第三行中,我们将一些内容添加到我们的新存储库中,并在第四行中提交该内容。