git Git克隆到当前目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30556438/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:04:29  来源:igfitidea点击:

Git cloning into current directory

git

提问by cheese5505

I am trying to clone a repository into my current directory. However, when I clone it with this command:

我正在尝试将存储库克隆到我的当前目录中。但是,当我使用此命令克隆它时:

git clone REPOURL .

it says:

它说:

fatal: destination path '.' already exists and is not an empty directory.

The folders that I am cloning into already exist and I just want to add files that I have in the git repo.

我要克隆到的文件夹已经存在,我只想添加我在 git repo 中的文件。

Is there any way I can do this?

有什么办法可以做到这一点吗?

Thanks

谢谢

回答by CodeWizard

You don't need to clone the repository, you need to add remote and then add the files to the repository.

您不需要克隆存储库,您需要添加远程,然后将文件添加到存储库。

git init
git remote add origin <remote_url>
git fetch --all --prune
git checkout master
git add -A .
git commit -m "Adding my files..."


In details:

详细说明:

You already have a remote repository and you want to add files to this repository.

您已经有一个远程存储库,并且想要向该存储库添加文件。

  1. First you have to "tell" git that the current directory is a git repository
    git init

  2. Then you need to tell git what is the url of the remote repository
    git remote add origin <remote_url>

  3. Now you will need to grab the content of the remote repository (all the content - branches, tags etc) git fetch --all --prune

  4. Check out the desired branch (master in this example)
    git checkout <branch>

  5. Add the new files to the current <branch>git add -A .

  6. Commit your changes git commit

  7. Upload your changes back to the remote repository git push origin <branch>

  1. 首先你必须“告诉”git当前目录是一个git仓库
    git init

  2. 然后你需要告诉git远程仓库的url是什么
    git remote add origin <remote_url>

  3. 现在您需要获取远程存储库的内容(所有内容 - 分支、标签等) git fetch --all --prune

  4. 检查所需的分支(本例中为 master)
    git checkout <branch>

  5. 将新文件添加到当前 <branch>git add -A .

  6. 提交您的更改 git commit

  7. 将更改上传回远程存储库 git push origin <branch>

回答by mainframer

You can use the git clone --bare origin_urlsyntax to just clone files(not repo foder).

您可以使用git clone --bare origin_url语法来克隆文件(而不是 repo foder)。

Try:

尝试:

mkdir tmp
cd tmp
git clone --bare origin_url ./

回答by Astabh

Edit: brain not working forgot about "."

编辑:大脑不工作忘记了“。”

What you are doing is asking git to clone the repo files into the current folder but the folder must be completely empty including no .git or you will get the error.

您正在做的是要求 git 将 repo 文件克隆到当前文件夹中,但该文件夹必须完全为空,包括没有 .git ,否则您将收到错误消息。

If you checkout this question it may help you achieve what you are trying to do Clone contents of a GitHub repository (without the folder itself)

如果您检查此问题,它可能会帮助您实现您正在尝试执行的操作克隆 GitHub 存储库的内容(没有文件夹本身)