链接来自另一个git存储库的单个文件 [英] Linking a single file from another git repository

查看:115
本文介绍了链接来自另一个git存储库的单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将另一个git存储库的单个文件链接到您自己的存储库?我不想要完整的存储库,只需要一个文件。使用 git submodule 似乎是正确的路线,但它希望抓住整件事情。

解决方案

考虑到git的工作单元是一个存储库(或者更准确地说是一个存储库 content ),我认为你不能轻松集成一个文件。 >

如果你不需要它的历史记录,你可以考虑简单地将它复制到你的回购中。

但是如果你需要历史记录,那么一些 git filter-branch (如 git:如何从项目中拆分库?filter-branch,subtree?)是按顺序排列的。尽管这只是一个文件,但似乎很费力。



理论上, git:符号链接/引用外部存储库中的文件提出了一个将子模块和符号链接相结合的解决方案。

(来自 $ b $ pre $ git submodule add / url / submodule / pavel-%C5%A0imerda> PavelŠimerda

< reponame>
$ ln -s< reponame> / path / to /< linked_file>
$ git add .gitmodules< linked_file>
$ git commit -m为< linked_file>添加一个符号链接,其中包含相应的子模块


How do you link a single file from another git repository to your own repository? I don't want the full repository, just a single file. Using git submodule seems like the right route to go, but it wants to grab the whole thing.

解决方案

Considering that the unit of work for git is a repository (or more precisely a repository content), I don't think you can easily integrate one file.

If you don't need its history, you could consider simply copy it in your repo.
But if you do need the history, then some git filter-branch (as in "git: How to split off library from project? filter-branch, subtree?") are in order. That seems a lot of effort for just one file though.

In theory, "git: symlink/reference to a file in an external repository" suggests a solution combining submodule and symlink.
(from Pavel Šimerda)

$ git submodule add /url/submodule/<reponame>
$ ln -s <reponame>/path/to/<linked_file>
$ git add .gitmodules <linked_file>
$ git commit -m "add a symbolic link to <linked_file> with the respective submodule"

这篇关于链接来自另一个git存储库的单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆