git clone 从另一个目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21045061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git clone from another directory
提问by SeekingAlpha
I am trying to clone repo from another directory.
我正在尝试从另一个目录克隆 repo。
Lets say I have one repo in C:/folder1
and C:/folder2
假设我有一个 repoC:/folder1
并且C:/folder2
I want to clone the work in folder1
into folder2
.
我想将工作克隆folder1
到folder2
.
What would I type into the command prompt to do this?
我会在命令提示符中输入什么来执行此操作?
It seems that often when cloning a URL is provided rather then a file path, however, at this moment I am just practicing and trying to get use to Git.
似乎通常在克隆 URL 时提供而不是文件路径,但是,此时我只是在练习并尝试使用 Git。
回答by Chris
cd /d c:\
git clone C:\folder1 folder2
From the documentation for git clone
:
For local repositories, also supported by git natively, the following syntaxes may be used:
/path/to/repo.git/ file:///path/to/repo.git/
These two syntaxes are mostly equivalent, except the former implies --local option.
对于本地存储库,也由 git 本地支持,可以使用以下语法:
/path/to/repo.git/ file:///path/to/repo.git/
这两种语法大部分是等价的,除了前者隐含 --local 选项。
回答by J.M.I. MADISON
None of these worked for me. I am using git-bash on windows. Found out the problem was with my file path formatting.
这些都不适合我。我在 Windows 上使用 git-bash。发现问题出在我的文件路径格式上。
WRONG:
错误的:
git clone F:\DEV\MY_REPO\.git
CORRECT:
正确的:
git clone /F/DEV/MY_REPO/.git
These commands are done from the folder you want the repo folder to appear in.
这些命令是从您希望 repo 文件夹出现的文件夹中完成的。
回答by Yasir Jan
It is worth mentioning that the command works similarly on Linux:
值得一提的是,该命令在 Linux 上的工作方式类似:
git clone path/to/source/folder path/to/destination/folder
回答by Yar
In case you have space in your path, wrap it in double quotes:
如果路径中有空格,请将其用双引号括起来:
$ git clone "//serverName/New Folder/Target" f1/
回答by Andreas Wederbrand
It's as easy as it looks.
它看起来很简单。
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 #)$
回答by Bleeding Fingers
Use git clone c:/folder1 c:/folder2
用 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.
回答by Mahmoud
I am using git-bash in windows.The simplest way is to change the path address to have the forward slashes:
我在 windows 中使用 git-bash。最简单的方法是更改路径地址以使用正斜杠:
git clone C:/Dev/proposed
P.S: Start the git-bash on the destination folder.
PS:在目标文件夹上启动 git-bash。
Path used in clone ---> c:/Dev/proposed
克隆中使用的路径 ---> c:/Dev/proposed
Original path in windows ---> c:\Dev\proposed
Windows 中的原始路径 ---> c:\Dev\proposed
回答by kris larson
Using the path itself didn't work for me.
使用路径本身对我不起作用。
Here's what finally worked for me on MacOS:
以下是最终在 MacOS 上对我有用的内容:
cd ~/projects
git clone file:///Users/me/projects/myawesomerepo myawesomerepocopy
This also worked:
这也有效:
git clone file://localhost/Users/me/projects/myawesomerepo myawesomerepocopy
The path itself worked if I did this:
如果我这样做,路径本身就起作用了:
git clone --local myawesomerepo myawesomerepocopy