Linux 没有项目文件夹的git clone
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17581379/
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 without project folder
提问by dzona
I have given access to server, and want to clone git repo into my root folder. But when I do git clone it will make me folder with project name, and my project folder is my root. I dont have access to my parent folder my root is
我已授予对服务器的访问权限,并希望将 git repo 克隆到我的根文件夹中。但是当我执行 git clone 时,它会为我创建一个带有项目名称的文件夹,而我的项目文件夹是我的根目录。我无权访问我的父文件夹,我的根是
/var/www/sites/mysite/
and when I do cloning folder structure will be
当我克隆文件夹结构时
/var/www/sites/mysite/mysite
采纳答案by rodrigo
git clone
accepts a last argument that is the destination directory, it is by default the name of the project but you can change it. In your case you probably want simply .
:
git clone
接受作为目标目录的最后一个参数,默认情况下它是项目的名称,但您可以更改它。在您的情况下,您可能只想.
:
$ git clone origin-url .
But note that, from man git-clone
:
但请注意,来自man git-clone
:
Cloning into an existing directory is only allowed if the directory is empty.
仅当目录为空时才允许克隆到现有目录。
回答by Sergey K.
You can clone your project into subfolder and them move all files including the .git
folder into the parent folder (your root).
您可以将项目克隆到子文件夹中,然后它们会将包括该.git
文件夹在内的所有文件移动到父文件夹(您的根)中。
回答by richo
You can also just setup a new repo and then the tracking remote and branch:
你也可以只设置一个新的 repo,然后跟踪远程和分支:
git init .
git remote add origin [email protected]:user/repo.git
git fetch origin
git checkout master
回答by Code-Apprentice
Remember that a git repository is simply the directory structure where you store it. This means that when you clone a repository into the wrong directory, you can simply move the directory contents anywhere else that you wish and the repository data is still intact. So for example, you can run the following commands from the command line:
请记住,git 存储库只是您存储它的目录结构。这意味着当您将存储库克隆到错误的目录中时,您可以简单地将目录内容移动到您希望的任何其他位置,并且存储库数据仍然完好无损。例如,您可以从命令行运行以下命令:
$ mv /var/www/sites/mysite/mysite/* /var/www/sites/mysite`
$ mv /var/www/sites/mysite/mysite/.* /var/www/sits/mysite`
$ rmdir /var/www/sites/mysite/mysite
回答by hobbydev
This is working well on Windows also.
这也适用于 Windows。
git init
git remote add origin [email protected]:user/repo.git
git pull origin master