克隆到非空 Git 目录
本文将介绍如何将 Git 仓库克隆到非空文件夹。当你要将远程仓库中的文件与当前本地仓库中的文件合并时,此操作会派上用场。
在 Git 中克隆到非空 Git 目录
克隆远程仓库很容易。我们使用下面的命令。
git clone <repository-url> <directory>
这会将远程仓库克隆到指定目录。但是,该目录应该是空的。
如果你尝试在非空仓库中克隆,你将收到致命警告
消息,如下所示。
pc@JOHN MINGW64 ~/Git (main)
$ git clone https://github.com/Wachira11ke/Delftscopetech.git
fatal: destination path 'Delftscopetech' already exists and is not an empty directory.
由于目录 Delftscopetech
已经存在并包含一些文件,我们不能使用 git clone
命令来克隆我们的仓库。
如果你不需要目录中的文件,你可以删除它们,但如果你想合并两个仓库中的文件,请使用下面的方法。
-
打开你要将远程仓库克隆到的目录。
“bash
cd / Delftscopetech1 -
使用此命令设置新仓库。
git init
-
添加远程仓库
git remote add origin https://github.com/Wachira11ke/Delftscopetech.git
-
拉取合并
git pull origin main --allow-unrelated-histories
例子:
pc@JOHN MINGW64 ~/Git (main)
$ cd \Delftscopetech1
pc@JOHN MINGW64 ~/Git/Delftscopetech1 (main)
$ git init
Initialized empty Git repository in C:/Users/pc/Git/Delftscopetech1/.git/
pc@JOHN MINGW64 ~/Git/Delftscopetech1 (master)
$ git remote add origin https://github.com/Wachira11ke/Delftscopetech.git
pc@JOHN MINGW64 ~/Git/Delftscopetech1 (master)
$ git pull origin master --allow-unrelated-histories
fatal: couldn't find remote ref master
pc@JOHN MINGW64 ~/Git/Delftscopetech1 (master)
$ git pull origin main --allow-unrelated-histories
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 610 bytes | 3.00 KiB/s, done.
From https://github.com/Wachira11ke/Delftscopetech
* branch main -> FETCH_HEAD
* [new branch] main -> origin/main
我们已经成功地将我们的远程仓库克隆到了我们的本地仓库中,并使用了一个非空目录。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站。本站所有源码与软件均为原作者提供,仅供学习和研究使用。如您对本站的相关版权有任何异议,或者认为侵犯了您的合法权益,请及时通知我们处理。