我正在尝试从另一个目录克隆回购。

假设在C:/folder1和C:/folder2中有一个repo

我想把文件夹1中的工作复制到文件夹2中。

我应该在命令提示符中输入什么来完成此操作?

似乎通常在克隆URL时提供的是URL而不是文件路径,然而,此时此刻我只是在练习并尝试使用Git。


当前回答

这和看起来一样简单。

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 #)$ 

其他回答

cd /d c:\
git clone C:\folder1 folder2

从git克隆的文档:

对于本地存储库,git也支持本地存储库,可以使用以下语法: / / repo.git / /路径 file:///path/to/repo.git/ 这两种语法基本上是等价的,除了前者暗示了—本地选项。

使用git克隆c:/folder1 c:/folder2

git clone [--template=<template_directory>] [-l] [-s] [--no-hardlinks]
[-q] [-n] [--bare] [--mirror] [-o <name>] [-b <name>] [-u <upload-pack>]
[--reference <repository>] [--separate-git-dir <git dir>] [--depth <depth>]
[--[no-]single-branch] [--recursive|--recurse-submodules] [--]<repository>
[<directory>]


<repository>

    The (possibly remote) repository to clone from.
    See the URLS section below for more information on specifying repositories.
<directory>

    The name of a new directory to clone into.
    The "humanish" part of the source repository is used if no directory 
    is explicitly given (repo for /path/to/repo.git and foo for host.xz:foo/.git).
    Cloning into an existing directory is only allowed if the directory is empty.

走这条路对我来说没用。

以下是我在MacOS上最终发挥作用的方法:

cd ~/projects
git clone file:///Users/me/projects/myawesomerepo myawesomerepocopy

这也奏效了:

git clone file://localhost/Users/me/projects/myawesomerepo myawesomerepocopy

如果我这样做,路径本身是有效的:

git clone --local myawesomerepo myawesomerepocopy

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

git clone path/to/source/folder path/to/destination/folder

这和看起来一样简单。

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 #)$