简体   繁体   English

git 克隆无项目文件夹

[英]git clone without project folder

I have given access to server, and want to clone git repo into my root folder.我已授予对服务器的访问权限,并希望将 git 存储库克隆到我的根文件夹中。 But when I do git clone it will make me folder with project name, and my project folder is my root.但是,当我执行 git 克隆时,它会生成带有项目名称的文件夹,并且我的项目文件夹是我的根目录。 I dont have access to my parent folder my root is我无权访问我的根文件夹

/var/www/sites/mysite/

and when I do cloning folder structure will be当我克隆文件夹结构时

/var/www/sites/mysite/mysite

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. git clone接受最后一个参数,即目标目录,默认情况下它是项目的名称,但您可以更改它。 In your case you probably want simply .在您的情况下,您可能只想要. :

$ 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.仅当目录为空时才允许克隆到现有目录。

You can also just setup a new repo and then the tracking remote and branch:你也可以只设置一个新的 repo,然后跟踪远程和分支:

git init .
git remote add origin git@github.com:user/repo.git
git fetch origin
git checkout master

This is working well on Windows also.这也适用于 Windows。

git init
git remote add origin git@github.com:user/repo.git
git pull origin master

Remember that a git repository is simply the directory structure where you store it.请记住,git 存储库只是您存储它的目录结构。 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:例如,您可以从命令行运行以下命令:

$ 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

您可以将项目克隆到子文件夹中,然后它们.git包括.git文件夹在内的所有文件移动到父文件夹(您的根)中。

git clone git@github.com:user/repo.git .

Notice the .注意. at the end of that command.在该命令的末尾。

Or Another way is或者另一种方法是

git init

git remote add origin git@github.com:user/repo.git

git pull origin master

The simplest way to achieve this is by initializing a Git repo in the directory you want to clone into and pull from the remote:实现这一点的最简单方法是在您要克隆到远程的目录中初始化 Git 存储库:

git init
git pull <remote-url>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM