如果我克隆到正在使用的目录中会发生什么?

时间:2015-06-03 09:51:15

标签: git

假设我的项目文件中有一个目录os。我可以使用git克隆到该目录中,例如$ git clone https://github.com/libgit2/libgit2 os并从repo和我现有的文件中获取混合文件,或者我克隆的目录是否不存在并由git创建?

3 个答案:

答案 0 :(得分:2)

您应该提供一个空目录或在git clone https://github.com/libgit2/libgit2目录中运行clone命令os,但是git将为libgit2 repo创建一个具有相同名称的新目录。 我想您要添加submodule git submodule add https://github.com/libgit2/libgit2

答案 1 :(得分:1)

因为git一般非常小心,永远不会无意中破坏文件,我的感觉告诉我这是不可能的,也不是一个好主意。但是,让我们试试:

$ mkdir p1
$ echo 'hi' > p1/foo.txt
$ cd p1/
$ git init
Initialized empty Git repository in /Users/joern/coding/git/tmp/p1/.git/
$ git add foo.txt
$ git commit -m'init'
[master (root-commit) ad640a7] init
 1 file changed, 1 insertion(+)
 create mode 100644 foo.txt
$ cd ..
$ mkdir p2
$ echo 'hallo' > p2/bar.txt
$ git clone p1 p2
fatal: destination path 'p2' already exists and is not an empty directory.

毫无疑问,这不起作用。如果您当前的os是git目录,那么您可能会在Raulucco's answer之后。如果您只想将os文件提供给上游存储库,我建议将您的lib克隆到新目录中,然后通过它复制旧文件中的所有文件。这样克隆中的文件就在git repo中,如果出错,你可以撤消它们:

$ mv os os.bak
$ git clone https://github.com/libgit2/libgit2 os
$ rsync -avPi os.bak/ os/
$ # review the os directory before finally doing
$ rm -r os.bak

答案 2 :(得分:1)

对于您提供的语法,应该是一个空目录。我使用了一个“dao”存储库来举例说明:

D:\sites-personal
λ mkdir dao

D:\sites-personal
λ cd dao\

D:\sites-personal\dao
λ touch file.txt

D:\sites-personal\dao
λ cd ..

D:\sites-personal
λ git clone git@myorigin/dao.git dao
fatal: destination path 'dao' already exists and is not an empty directory.
相关问题