来自另一个目录的git clone

See*_*pha 137 git git-clone

我正在尝试从另一个目录克隆repo.

可以说我有一个回购C:/folder1C:/folder2

我想将工作克隆folder1folder2.

我会在命令提示符中键入什么来执行此操作?

似乎经常提供克隆URL而不是文件路径,但是,此时我正在练习并尝试使用Git.

Chr*_*ris 148

cd /d c:\
git clone C:\folder1 folder2
Run Code Online (Sandbox Code Playgroud)

从以下文档git clone:

对于本地存储库,也由本机git支持,可以使用以下语法:

/path/to/repo.git/

file:///path/to/repo.git/
Run Code Online (Sandbox Code Playgroud)

这两种语法大多是等价的,除了前者暗示--local选项.

  • @grahamesd,你真的不需要将网络文件夹映射为驱动器,因为GIT可以用这样的方式克隆它:`git clone // pc_name/git` (4认同)

J.M*_*SON 15

这些都不适合我.我在windows上使用git-bash.发现问题出在我的文件路径格式上.

错误:

git clone F:\DEV\MY_REPO\.git
Run Code Online (Sandbox Code Playgroud)

正确:

git clone /F/DEV/MY_REPO/.git
Run Code Online (Sandbox Code Playgroud)

这些命令是从您希望repo文件夹出现的文件夹中完成的.

  • 对于 git-bash,您可以使用反斜杠“/”或双斜杠“\\\”。但没有单斜线。 (2认同)

Yas*_*Jan 12

值得一提的是,该命令在Linux上的工作方式类似:

git clone path/to/source/folder path/to/destination/folder
Run Code Online (Sandbox Code Playgroud)


And*_*and 7

它看起来很简单.

14:27:05 ~$ mkdir gittests
14:27:11 ~$ cd gittests/
14:27:13 ~/gittests$ mkdir localrepo
14:27:20 ~/gittests$ cd localrepo/
14:27:21 ~/gittests/localrepo$ git init
Initialized empty Git repository in /home/andwed/gittests/localrepo/.git/
14:27:22 ~/gittests/localrepo (master #)$ cd ..
14:27:35 ~/gittests$ git clone localrepo copyoflocalrepo
Cloning into 'copyoflocalrepo'...
warning: You appear to have cloned an empty repository.
done.
14:27:42 ~/gittests$ cd copyoflocalrepo/
14:27:46 ~/gittests/copyoflocalrepo (master #)$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
14:27:46 ~/gittests/copyoflocalrepo (master #)$ 
Run Code Online (Sandbox Code Playgroud)


Yar*_*Yar 7

如果路径中有空格,请用双引号括起来:

$ git clone "//serverName/New Folder/Target" f1/
Run Code Online (Sandbox Code Playgroud)


kri*_*son 5

使用路径本身对我不起作用。

以下是最终在 MacOS 上对我有用的内容:

cd ~/projects
git clone file:///Users/me/projects/myawesomerepo myawesomerepocopy
Run Code Online (Sandbox Code Playgroud)

这也有效:

git clone file://localhost/Users/me/projects/myawesomerepo myawesomerepocopy
Run Code Online (Sandbox Code Playgroud)

如果我这样做,路径本身就起作用了:

git clone --local myawesomerepo myawesomerepocopy
Run Code Online (Sandbox Code Playgroud)