首页 > 解决方案 > 从 GitHub 存储库中检出文件夹的内容,而不是使用 sparse-checkout 检出文件夹本身

问题描述

我在 GitHub 上创建了一个存储库,其中包含我的一个小项目的文件。这个存储库的内容都来自不同的位置,因此我不想查看整个存储库,而只想查看一个子目录。

经过一番调查,我发现有稀疏结帐功能,它应该完全符合我的要求。我发现的所有教程的问题是,我只能签出子目录,而不是子目录的内容。

示例:我的存储库有“/patches/”,其中包含一些文件。我的本地 PC 也有一个文件夹“C:\wherever\patches”。在这个文件夹中,我想查看补丁的内容,但每次它都会在我的补丁文件夹中查看一个文件夹补丁。

目标具有以下结构:

C:\wherever\patches\
C:\wherever\patches\.git\ 
    (the .git folder should be inside the patches, not outside next to it - 
    i want to check out the contents, not the folder)
C:\wherever\patches\<rest of the content>

到目前为止我尝试了什么:在我的本地“补丁”文件夹中运行 Git Bash:

git init
git sparse-checkout init
git sparse-checkout set patches/
git remote add -f origin https://github.com/BlackMagicCoding/PokemonRubySapphire.git
git pull origin main

为“git sparse-checkout set”命令尝试了不同的值,但对我没有任何作用。

标签: gitgithubsparse-checkoutgit-sparse-checkout

解决方案


推荐阅读