运行 git init 两次是初始化存储库还是重新初始化现有存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5149694/
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
Does running git init twice initialize a repository or reinitialize an existing repo?
提问by Mr. L
What happens to an existing git repository when you issue git init
again?
当您git init
再次发出时,现有的 git 存储库会发生什么?
I created a repository with git init
. Created a file, add, commit. Check the status (nothing to commit). Then created another file, check the status and I can see it's untracked as expected.
我创建了一个存储库git init
。创建文件,添加,提交。检查状态(无需提交)。然后创建了另一个文件,检查状态,我可以看到它没有按预期跟踪。
Then, say by mistake, I run git init
again and I get Reinitialise existing Git repository message.
然后,错误地说,我git init
再次运行并收到Reinitialise existing Git repository 消息。
Tried git status
, but it shows the same. So what really happens?
试过了git status
,但显示相同。那么到底发生了什么?
Can reinitialising an existing git repository this way be harmful or helpful? Why can we git init
inside an existing repository?
以这种方式重新初始化现有的 git 存储库是否有害或有帮助?为什么我们可以git init
在现有的存储库中?
回答by coreyward
回答by Greg Hewgill
This is described in the git init
documentation:
这在git init
文档中描述:
Running git initin an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git initis to pick up newly added templates.
在现有存储库中运行git init是安全的。它不会覆盖已经存在的东西。重新运行git init 的主要原因是选择新添加的模板。
回答by Joe
Since v1.7.5 (b57fb80a7), git init
in an existing repo has also allowed moving the .git
directory:
从 v1.7.5 ( b57fb80a7) 开始,git init
在现有的 repo 中也允许移动.git
目录:
The primary reason for rerunning 'git init' is to pick up newly added templates (or to move the repository to another place if --separate-git-dir is given).
重新运行 'git init' 的主要原因是选择新添加的模板(或者如果给定了 --separate-git-dir,则将存储库移动到另一个地方)。
'Picking up newly-added templates' means that any templates which have not already been copied from the template directorywill now be copied into the existing git directory.
“拾取新添加的模板”意味着任何尚未从模板目录中复制的模板现在都将复制到现有的 git 目录中。
'Moving the repository to another place' means that, if --separate-git-dir
points to somewhere else, the existing .git
directory will be moved there and replaced by a link.
'Moving the repository to another place'意味着,如果--separate-git-dir
指向其他地方,现有.git
目录将被移动到那里并被链接替换。
回答by Khadim Rana
it's mean that you already initialized the git. because you already upload a file on github from this path. you check the path then a folder is created by name of .git. That is why you don't requried again to initialized git. you can go to direct next step
这意味着您已经初始化了 git。因为你已经从这个路径上传了 github 上的文件。您检查路径,然后会创建一个名为 .git 的文件夹。这就是为什么您不需要再次初始化 git 的原因。你可以直接下一步
git add .
git 添加。