Git 如果我克隆到正在使用的目录中会发生什么?
假设我的项目文件中有一个目录Git 如果我克隆到正在使用的目录中会发生什么?,git,Git,假设我的项目文件中有一个目录os。我可以用git克隆到该目录中吗,例如,$git clonehttps://github.com/libgit2/libgit2 os并从repo和我的现有文件中混合获取文件,或者我克隆到的目录必须不存在并且由git创建?您应该提供一个空目录或运行clone命令git clonehttps://github.com/libgit2/libgit2在os目录中,但git将使用相同的名称为libgit2 repo创建一个新目录。 我想您需要添加一个git子模块addh
os
。我可以用git克隆到该目录中吗,例如,$git clonehttps://github.com/libgit2/libgit2 os
并从repo和我的现有文件中混合获取文件,或者我克隆到的目录必须不存在并且由git创建?您应该提供一个空目录或运行clone命令git clonehttps://github.com/libgit2/libgit2
在os
目录中,但git将使用相同的名称为libgit2 repo创建一个新目录。
我想您需要添加一个
git子模块addhttps://github.com/libgit2/libgit2
您应该提供一个空目录或运行clone命令git clonehttps://github.com/libgit2/libgit2
在os
目录中,但git将使用相同的名称为libgit2 repo创建一个新目录。
我想您需要添加一个
git子模块addhttps://github.com/libgit2/libgit2
由于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目录,那么您可能正在寻找它。如果您只想将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
由于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目录,那么您可能正在寻找它。如果您只想将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
对于您提供的语法,应该是一个空目录。我使用了一个“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.
对于您提供的语法,应该是一个空目录。我使用了一个“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.
对子模块的引用是关键。只要那是OP想要的,他状态很好。不好的是,如果他想使用回购协议中的文件和其他未管理的文件进行操作。这不是一个好主意。我同意你不能在同一个目录中混合来自不同repo的文件。这是一种糟糕的方法,因为其目标是独立管理每一笔回购交易。对子模块的引用是关键。只要那是OP想要的,他状态很好。不好的是,如果他想使用回购协议中的文件和其他未管理的文件进行操作。这不是一个好主意。我同意你不能在同一个目录中混合来自不同repo的文件。这是一种糟糕的方法,因为其目标是独立管理每份回购协议