如果我只想专注于linux
的某个模块,比如perf
,我怎么能直接fork或者下载perf
模块相关的来自 github 的文件?我尝试了以下命令:
c:\work> git clone https://github.com/torvalds/linux/tree/master/tools/perf
Cloning into 'perf'...
fatal: repository 'https://github.com/torvalds/linux/tree/master/tools/perf/' not found
但是不行。
最佳答案
您需要结合使用 Git 的两个相对较新的功能。
第一个是sparse-checkout(自 Git 1.7.0 起可用)。 Sparse-checkout 允许你通过明确指定你想要在你的 repo 中拥有哪些目录来保持你的工作空间干净。然而,它不会影响整个存储库的大小,下载 1GB 的所有 Linux 内核源代码是一件令人头疼的事情。这就是为什么您需要第二个功能:
第二个特性是浅克隆(自 Git 1.9.0 起可用)。它允许您使用 --depth
参数从一个仅保留 n 个历史变更集的 repo 中提取。
因此,如果您只想获取 tools/perf
模块,这是要走的路:
git init
git remote add origin https://github.com/torvalds/linux.git
git config core.sparsecheckout true
echo "tools/perf" >> .git/info/sparse-checkout
git pull --depth=1 origin master
瞧!您的存储库中唯一的目录是 tools/perf
,您只需下载 136MB。
关于linux - 我怎样才能从 linux 内核中克隆一个模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28403538/