git - 从 Git 存储库中 fork 一个文件而不克隆存储库

标签 git

有没有办法在不克隆整个仓库的情况下从外部 Git 仓库中 fork 一个文件?

最佳答案

最接近的方法是使用 sparse checkout ,这意味着使用 Git 1.7+ 并且您仍然需要克隆存储库(或使用 clone--depth 选项进行浅克隆)。主要借自 this answer ,您可以执行以下操作:

git clone --no-checkout <URL to git repo> myrepo
cd myrepo
git config core.sparseCheckout true
vim .git/info/sparse-checkout # Add files you want checked out
git checkout <branch you want>

如果你有 Git 版本 1.7.7-rc0 或更高版本,你可以使用 clone 命令设置配置选项:

git clone --config core.sparseCheckout=true --no-checkout <URL to git repo> myrepo

另请参阅以下内容:

关于git - 从 Git 存储库中 fork 一个文件而不克隆存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8442818/

相关文章:

git - 将整个git分支重新设置为孤立分支,同时保持提交树完整

git - 在 super 项目中自动提交 git 子模块哈希

git - TortoiseGit:添加以忽略已提交的 gen 和 bin 文件夹

node.js - 推送失败! [远程拒绝] master -> master(预接收 Hook 被拒绝)

Git:错误如果 "No newline at end of file"

c++ - 处理 Github 存储库中的外部 C/C++ 代码库

git - 如何在 git 命令提示符下添加时间

git - 如何只保留 git rebase 中的头部更改

git - 如果它们指向 Git 中的相同提交,则基于分支 foo 或 bar 创建分支之间有什么区别吗?

git - 将 Mercurial 文件夹转换为 Git 存储库