如何删除裸“git”存储库中的唯一分支



我正在试验一些githooks,所以我设置了一个本地裸存储库,其中包含从hooks到其他地方存储的钩子的符号链接。

我已经将master分支推送到git repo,当然,钩子失败了。:)

我想将git回购重置为零,而不必删除它,也不必重新创建符号链接等

如果主分支是存储库中唯一的分支,我该如何删除它

$ git branch -d master
error: Cannot delete the branch 'master' which you are currently on.

要删除master引用,请使用git update-ref -d refs/heads/master

为什么不应该rm /refs/heads/master

packed-refs可能存在,因此rm有时无法按预期工作。

顺便说一句,如果你可以创建一个新的空回购,那么重置有什么意义?只需使用git init --bare repo.git即可。

通常,您不需要删除分支,您可以使用git reset --hard REV将其设置为所需的新修订版。然而,如果我正确理解yuo,您希望将其重置为"无",即重置为git init首次调用后的状态。git似乎不允许您这样做,但只需删除.git/heads/refs/master就可以获得类似的效果。以下是一个新创建的回购中的演示:

[~/x]$ git init
Initialized empty Git repository in /home/author/x/.git/
[~/x]$ touch a      
[~/x]$ git add a
[~/x]$ git commit -m foo
[master (root-commit) 5fcc99c] foo
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
[~/x]$ git log
commit 5fcc99cc396cf5bc2c2fa9edef475b0cc9311ede
Author: ...
Date:   Mon Sep 3 12:40:15 2012 +0200
    foo

在这里,你可能想这样做,但git不允许:

[~/x]$ git reset --hard HEAD^
fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

但是,您可以这样做:

[~/x]$ rm .git/refs/heads/master 

通过提交来检查它是否有效

[~/x]$ touch b
[~/x]$ git add b
[~/x]$ git commit -m 'new history'
[master (root-commit) 0e692b9] new history
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
 create mode 100644 b
[~/x]$ git log
commit 0e692b9bb77f526642dcdf86889ec15dfda12be0
Author: ...
Date:   Mon Sep 3 12:40:52 2012 +0200
    new history
[~/x]$ git branch 
* master

最新更新