我想从另一个目录克隆存储库。
假设我有一个存储库在C:/folder1
和C:/folder2
我想将folder1
中的工作克隆到folder2
中。
要执行此操作,应在命令提示符中键入什么?
似乎在克隆时通常提供URL而不是文件路径,但是,此时我只是练习并尝试使用Git。
cd /d c:\
git clone C:\folder1 folder2
根据git clone文档:
对于本地仓库,git原生支持以下语法:
/path/to/repo.git/ file:///path/to/repo.git/
这两种语法在大多数情况下是等价的,除了前一种意味着--local选项。
git clone //pc_name/git
,这种方法相当好。 - vladimir_kigit clone ../some/path
。或者,您可以管理您的远程仓库。像这样克隆应该会自动配置一个“origin”远程仓库以供将来使用,例如 fetch
或 push
提交。 - Chrisgit clone path/to/source/folder path/to/destination/folder
git clone path/to/source/folder
命令。 - Sahin这些方法都对我无效。我正在 Windows 上使用 git-bash。
后来发现问题出在我的文件路径格式上。
错误的路径格式为:
git clone F:\DEV\MY_REPO\.git
正确:
git clone /F/DEV/MY_REPO/.git
这些命令需要在你想要存储库文件夹出现的文件夹中执行。
/
或双斜杠 \\\
。但不能使用单斜杠。 - Elad Weiss这不难如你所见。
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 #)$
$ git clone "//serverName/New Folder/Target" f1/
直接使用路径对我不起作用。
这是在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
git clone 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.
我正在Windows中使用git-bash。
最简单的解决方案是将源文件夹路径中的 \
替换为正斜杠(/
):
例如:c:\dev\source
将会变成 c:/dev/source
在目标文件夹上启动git-bash。
使用正斜杠的源文件夹路径运行git clone:
git clone c:/dev/source
git clone C:\folder1\.git folder2
。你需要从想要出现folder2的目录中运行该命令。 - Akashfile:\\
。请参见此链接:https://dev59.com/R1oU5IYBdhLWcg3we24R - Jacob H