【问题标题】:Why does git clone sometimes create a .git directory, and sometimes not?为什么 git clone 有时会创建一个 .git 目录,有时不会?
【发布时间】:2020-08-07 19:59:02
【问题描述】:

之前至少有 3 个问题解释了如何在没有 .git 目录的情况下克隆存储库:

从这些问题来看,您似乎不能只运行git clone 并在没有.git 目录的情况下克隆存储库。

然而,在我克隆的大多数 repos 中,例如下面命令中的那个,没有创建 .git 目录。

git clone https://github.com/scotch-io/scotch-box.git

什么决定了直接的git clone 命令是否创建.git 目录?

【问题讨论】:

  • 在我克隆了你提供的 repo 之后,我有一个 .git 目录。因此,我能想象的唯一没有 .git 目录的情况是一个裸存储库。但即使你克隆了这个裸仓库,git 也会创建一个 .git 文件夹。 git必须正常工作。
  • 哈哈。从未见过没有 .git 目录的 git 存储库。不可能。可能只是隐藏在你的箱子里。

标签: git git-clone


【解决方案1】:

总是git clone 之后有一个.git 目录。没有例外。如果您看不到它,则它被隐藏(如何发生取决于您的操作系统。Linux 上的ls 不显示以点开头的文件/目录。您必须使用ls -a。)

.git 目录是必不可少的,因为它包含 git 使用的所有文件和信息。

这是您提到的git-clone 之后发生的情况:

/tmp % git clone https://github.com/scotch-io/scotch-box.git
Cloning into 'scotch-box'...
remote: Counting objects: 83, done.
remote: Total 83 (delta 0), reused 0 (delta 0), pack-reused 83
Unpacking objects: 100% (83/83), done.
Checking connectivity... done.
/tmp % cd scotch-box 
/tmp/scotch-box (git)-[master] % la
total 40K
drwxr-xr-x 4 t t 4.0K 12. Aug 14:10 .
drwxrwxrwt 8 root  root   12K 12. Aug 14:10 ..
drwxr-xr-x 7 t t 4.0K 12. Aug 14:10 .git
-rw-r--r-- 1 t t   18 12. Aug 14:10 .gitignore
-rw-r--r-- 1 t t 7.4K 12. Aug 14:10 README.md
-rw-r--r-- 1 t t  480 12. Aug 14:10 Vagrantfile
drwxr-xr-x 2 t t 4.0K 12. Aug 14:10 public

【讨论】:

    【解决方案2】:

    您确定要在正确的位置寻找.git 吗?当您像git clone https://github.com/scotch-io/scotch-box.git 那样进行克隆时,repo 实际上是在目录scotch-box 中克隆的,因此.git 将位于scotch-box/.git

    另一方面,做:

    git 克隆 https://github.com/scotch-io/scotch-box.git .

    注意最后的. - 将在当前文件夹中克隆(如果这还不是 git repo)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-08
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 2019-06-10
      • 2011-06-30
      • 1970-01-01
      相关资源
      最近更新 更多