繁体   English   中英

如何从 linux 内核克隆模块?

[英]How can I clone a module from linux kernel?

如果我只想专注于linux一个模块,例如perf ,我如何只从github fork 或下载perf模块相关文件? 我尝试了以下命令:

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 的两个相对较新的功能。

第一个是稀疏结帐(自 Git 1.7.0 起可用)。 Sparse-checkout 允许你通过明确指定你想要在你的仓库中拥有哪些目录来保持你的工作区干净。 然而,它不会影响整个存储库的大小,下载 1GB 的所有 Linux 内核源代码是一件令人头疼的事。 这就是您需要第二个功能的原因:

第二个特性是浅克隆(从 Git 1.9.0 开始可用)。 它允许您使用--depth参数从仅保留历史记录中的n 个变更集的存储库中--depth

因此,如果您只想获得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

瞧! 你的 repo 中唯一的目录是tools/perf ,你只需要下载 136MB。

添加到 Luboš 的回答中,因为我也只需要 perf,但需要特定的标记版本。 标签不会出现在浅克隆中。 因此,您需要准确地查看标记版本的 repo。

代替

git pull --depth=1 origin master

git fetch --depth=1 origin v4.19
git checkout FETCH_HEAD

如果您想要的版本是 4.19。

如果要实际构建特定的 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
echo "tools/scripts" >> .git/info/sparse-checkout
echo "tools/build" >> .git/info/sparse-checkout
echo "tools/include" >> .git/info/sparse-checkout
echo "tools/include" >> .git/info/sparse-checkout
echo "tools/arch" >> .git/info/sparse-checkout
echo "tools/lib" >> .git/info/sparse-checkout
git fetch --depth=1 origin v4.19
git checkout FETCH_HEAD
make -C tools/perf

现在(如果您安装了所有依赖项):

$ ./tools/perf/perf --version
perf version 4.19.g84df

暂无
暂无

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

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