简体   繁体   中英

How can I clone a module from linux kernel?

If I only want to focus on a module of linux , such as perf , how can I just fork or download perf module related files from github ? I have tried the following command:

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

But it can't work.

You need to use a combination of two relatively new features of Git.

The first is sparse-checkout (available since Git 1.7.0). Sparse-checkout allows you to keep your workspace clean by explicitely specifying which directories you want to have in your repo. However it does not affect the size of the whole repository and downloading 1GB of all Linux kernel sources is pain in the neck. That's why you need the second feature:

The second feature is shallow clone (available since Git 1.9.0). It allows you to pull from a repo keeping only n changesets in the history using --depth parameter.

So if you want to get only the tools/perf module this is the way to go:

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

Voila! The only directory in your repo is tools/perf and you had to download only 136MB.

Adding to Luboš' answer, since I also needed only perf, but a specific tagged version. The tags don't appear in the shallow clone. So you need to check out the repo exactly at the tagged version.

Replace

git pull --depth=1 origin master

with

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

if the version you want is 4.19.

If you want to actually build that specific perf version you'll need more folders:

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

Now (if you have all the dependencies installed):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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