删除或删除远程Git仓库中的所有历史记录,提交和分支? [英] Delete or remove all history, commits, and branches from a remote Git repo?

查看:1171
本文介绍了删除或删除远程Git仓库中的所有历史记录,提交和分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读并尝试了很多Git命令的建议和讨论,并持续了好几天。看起来确实没有一种简单而全面的方法来<远>使远程Git仓库完全清空 - 没有分支,没有参考,没有对象,没有文件,没有任何东西。

是的,我承认可以删除并重新创建回购 - 如果有人对原产地具有这种权限(我不这样做),但那是不是重点。它是如何完成的? Git命令的实际组合将实际执行此操作,将处于未处理状态的回购准备好接收我们希望推入其中的任何内容,基本上没有大小(或最小大小处女回购)



请不要告诉我这不应该做,或者我们必须通知所有用户等即可。我知道这一切。 我只是想开始全新的

解决方案

- 镜像标记(强调我的):


   -  mirror 
code>

不是指定每个ref都要推送,而是指定refs /(包括但不限于 refs / heads / refs / remotes / refs / tags / )镜像到远程存储库。新创建的本地参考将被推送到远端,本地更新的参考将在远端强制更新, 已删除的参考将从远端 删除。如果设置了配置选项 remote.< remote> .mirror ,则这是默认设置。


如果您的repo位于GitHub上,则当尝试推送时,如果 master 设置为默认分支,则会出现此错误:

  $ mkdir practice; CD练习; 
$ git init; git remote add origin git@github.com:user / practice.git;

$ git push origin --mirror
remote:error:拒绝删除当前分支:refs / heads / master
至git@github.com:user / practice。 git
! [远程拒绝]主控(删除当前分支禁止)
错误:未能将某些参考推送到'git@github.com:user / practice.git'

我通过初始提交,然后推送来解决此问题。



强制性警告:当然,这将完全清除所有历史记录并在远程回购中提交 - 所有引用,所有分支,所有标记等。确保这实际上是您想要执行的操作。当然,在做这件事之前,你总是可以做一个远程仓库的备份克隆,以防你因为某种原因想保留它。



另外请注意,没有提交实际上将被立即删除。它们只会成为悬空的提交,这意味着它们无法从分支中访问。最终,他们会通过Git回收站收集垃圾,但如果您有权访问远程回购站点,则可以使用 git gc 手动启动垃圾回收。


I've read and tried lots of Git command recommendations and discussion, going on over several days now. It appears that there really is no simple, comprehensive way to make a remote Git repo completely empty -- no branches, no refs, no objects, no files, no nothing.

Yes, I recognize that one could delete and recreate the repo -- if one had that kind of permissions on the origin (which I don't), but that is not the point. How is it done? What combination of Git commands will actually do this, leaving the repo in a virgin state ready to receive whatever we wish to push into it, and with essentially no size (or the minimal size of a virgin repo)?

Please don't tell me this shouldn't be done, or that we have to inform all users, etc. I know all that. I just want to start completely fresh.

解决方案

You might want to try pushing an empty local repo with the --mirror flag (emphasis mine):

--mirror

Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/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. This is the default if the configuration option remote.<remote>.mirror is set.

If your repo is on GitHub, you'll get this error if master is set to the default branch when trying to push:

$ mkdir practice; cd practice;
$ git init; git remote add origin git@github.com:user/practice.git;

$ git push origin --mirror
remote: error: refusing to delete the current branch: refs/heads/master
To git@github.com:user/practice.git
 ! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'git@github.com:user/practice.git'

I got around this by making an initial commit, then pushing.

Obligatory Warning: this will, of course, completely wipe out all of your history and commits in your remote repo—all references, all branches, all tags, etc. Make sure this is actually what you want to do. Of course, you can always make a backup clone of your remote repo before doing this, in case you want to keep it around for whatever reason.

Also note that none of the commits will actually be deleted right away. They'll just become dangling commits, meaning that they're not reachable from a branch. Eventually they'll get garbage collected by Git repos, but if you have access to your remote repo, you can manually start the garbage collection with git gc.

这篇关于删除或删除远程Git仓库中的所有历史记录,提交和分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆