简体   繁体   English

是否可以将不带.git文件夹的git repo克隆到现有的非空目录中

[英]Is it possible to clone a git repo without the .git folder, into an existing non empty directory

I have an odd use case, and am not very familiar with Git. 我有一个奇怪的用例,并且对Git不太熟悉。 I have two git repos; 我有两个git repos; repo one which is empty, and repo two which has files. 仓库1是空的,仓库2是有文件的。 I also have a folder ./foo. 我也有一个文件夹./foo。 I want something similar to this: 我想要类似的东西:

cd ./foo
git clone repo_one .
git clone repo_two . (I just want the files from repo_two. No .git folder or anything)
git add --a
git push repo_one

or maybe 或者可能

cd ./foo
git clone repo_two .
rm ./.git
git clone repo_one . (possible in an existing directory though?)

Are either of these possible? 这些都有可能吗? All I really care about is the end result; 我真正关心的只是最终结果。 that .foo is linked to repo_one, but contains the files from repo_two. 该.foo链接到repo_one,但包含来自repo_two的文件。

Since you've cloned both the Git repos, execute the following command on repo #2 to export (or archive) it without its .git folder: 由于您已经克隆了两个Git仓库,因此在仓库2上执行以下命令以导出(或存档)它的.git文件夹:

git archive master | tar -x -C /path/inside/repo1

The final sequence of events would be something like this: 事件的最终顺序是这样的:

cd foo
git clone repo_one
git clone repo_two
cd repo_two
git archive master | tar -x -C ../repo_1

git clone has an option --separate-git-dir= which puts the .git directory somewhere else, but it creates a file named .git in the checkout directory, which references the relocated .git-directory. git clone有一个选项--separate-git-dir= ,它将.git目录放在其他位置,但是它在checkout目录中创建了一个名为.git的文件,该文件引用了已重定位的.git-directory。

https://git-scm.com/docs/git-clone#git-clone---separate-git-dirltgitdirgt https://git-scm.com/docs/git-clone#git-clone---separate-git-dirltgitdirgt

查看有关捆绑包和存档的这篇有用的博客文章: https : //www.perforce.com/blog/git-beyond-basics-bundle-and-archive

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

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