23

我刚刚git init在一个已经存在的 git repo 上运行。
结果是重新初始化现有的 Git 存储库

我该如何撤消此操作?
谢谢!

4

3 回答 3

39

不需要 - 这样做很安全。从文档中

Running git init in an existing repository is safe. 
It will not overwrite things that are already there. 
The primary reason for rerunning git init is to pick up newly added templates.

模板是文件,例如作为 git 一部分的示例挂钩和示例文件。如果您在创建 repo 后更新了 git 并且这些文件已更改,它们将不会被更新 - 只会添加新文件。由于这些文件实际上都不是“活动的”,因此这应该是完全安全的。

于 2013-10-16T07:55:47.650 回答
0

所以这可能是第一个错误。该错误来自您还没有真正使用过 git 的事实(抱歉,尚未测试该场景)。

所以要修复,运行

git config --global user.email "you@example.com"

然后

git config --global user.name "Your Name"

进而

git remote rm origin

一切都应该很好。对不起,令人困惑的错误

于 2020-02-13T13:59:31.537 回答
-1

要撤消 git init 所做的更改,您应该删除 git 存储库。请按照以下步骤完成工作。

对于 Linux

rm -rf .git

对于 Windows

rmdir .git

参考 https://www.w3docs.com/snippets/git/how-to-delete-git-repository-created-with-init.html

于 2021-02-20T07:16:34.550 回答