Kernel Hackers' Guide to git

转载 2007年09月17日 15:34:00

This tutorial is a cookbook of recipes getting up and running with Linus's source code management (SCM) software, "git." Its targetted mainly at Linux kernel hackers, though others may find it useful.

<script type="text/javascript"><!-- google_ad_client = "pub-0316247916390367"; google_ad_width = 120; google_ad_height = 600; google_ad_format = "120x600_as"; google_ad_type = "text_image"; google_ad_channel ="8548579839"; google_color_border = "000000"; google_color_bg = "F0F0F0"; google_color_link = "0000FF"; google_color_url = "008000"; google_color_text = "000000"; //--></script> <script src="" type="text/javascript"> </script> <iframe width="120" scrolling="no" height="600" frameborder="0" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" src=";dt=1190011758578&amp;lmt=1169662894&amp;format=120x600_as&amp;output=html&amp;correlator=1190011758578&amp;channel=8548579839&amp;;color_bg=F0F0F0&amp;color_text=000000&amp;color_link=0000FF&amp;color_url=008000&amp;color_border=000000&amp;ad_type=text_image&amp;;cc=100&amp;ga_vid=760120697.1190011759&amp;ga_sid=1190011759&amp;ga_hid=247721911&amp;flash=9&amp;u_h=800&amp;u_w=1280&amp;u_ah=772&amp;u_aw=1280&amp;u_cd=32&amp;u_tz=480&amp;u_his=1&amp;u_java=true&amp;u_nplug=9&amp;u_nmime=28" name="google_ads_frame" style="display: none;"></iframe>

Table of Contents

Getting Started

Installing git

git requires bootstrapping, since you must have git installed in order to check out git.git (git repository), and linux-2.6.git (kernel repository). You may find that your distribution already provides a usable version of git. If so, try that first.

  • Fedora Core 3 and later: git-core package is in Fedora Extras

    yum install git-core

If your distro doesn't have a package already, you should start by downloading a daily snapshot of the git source code.

Download the latest stable release from:

tarball build-deps: zlib, libcurl, libcrypto (openssl)

install tarball:

unpack && make && sudo make prefix=/usr/local install

After reading the rest of this document, come back and update your copy of git to the latest: git://

Download a linux kernel tree for the very first time

$ git-clone git:// linux-2.6

NOTE: The kernel tree is very large. This constitutes downloading several hundred megabytes of data.

Basic Tasks

Update local kernel tree to latest 2.6.x upstream ("fast-forward merge")

$ cd linux-2.6
$ git pull git://

Undo all local modifications:

$ git checkout -f

Check in your own modifications (e.g. do some hacking, or apply a patch)

# go to repository
$ cd linux-2.6

# make some modifications
$ vi drivers/net/sk98lin/skdim.c

# NOTE: Run git-add and git-rm if adding or removing files.

# check in all modifications
$ git commit -a

List all changes in working dir, in diff format.

Display changes since last git-update-index:

$ git diff

Display changes since last commit:

$ git diff HEAD

Obtain summary of all changes in working dir

$ git status

List all changesets

$ git log

List all changesets belonging to a specific file

(in this case, net/ieee80211/ieee80211_module.c)
$ git-whatchanged net/ieee80211/ieee80211_module.c


List all branches

$ git branch

Make desired branch current in working directory

$ git checkout $branch

Create a new branch, and make it current

$ git checkout -b my-new-branch-name master

Examine which branch is current

$ git branch

(the branch with the asterisk '*' beside it is current)

Obtain a diff between current branch, and master branch

In most trees with branches, .git/refs/heads/master contains the current 'vanilla' upstream tree, for easy diffing and merging. (in trees without branches, 'master' simply contains your latest changes)

$ git diff master..HEAD

(this is equivalent to git diff HEAD, when used with HEAD branch)

Obtain a list of changes between current branch, and master branch

$ git log master..HEAD

(this is equivalent to git log, when used with HEAD branch)

or rather than full changeset descriptions, obtain a one-line summary of each changes:
$ git log master..HEAD | git shortlog

Merge changes from one branch into another

Let us suppose that you do work on branch A and branch B, and after work on those two branches is complete, you merge the work into mainline branch M.
$ git checkout M	# switch to branch M
$ git pull . A # merge A into M
$ git pull . B # merge B into M

Misc. Debris

Apply all patches in a Berkeley mbox-format file

First, make sure that the tools subdirectory of the git-core repository is in your PATH.

$ cd my-kernel-tree-2.6
$ git-applymbox /path/to/mbox /path/to/signoff.txt

The file /path/to/mbox is a Berkeley mbox file, containing one or more patches to be committed to the git repository. The optional file /path/to/signoff.txt is the text file that is appended to each changeset description. For the Linux kernel, this typically includes the

Signed-off-by: Your Name <>

line that is common to almost all kernel submissions.

Don't forget to download tags from time to time.

git pull only downloads sha1-indexed object data, and the requested remote head. This misses updates to the .git/refs/tags/ and .git/refs/heads/ directories. For tags, run git pull



Kernel Hackers Guide to git (v3)

Kernel Hackers' Guide to git
  • sanlinux
  • sanlinux
  • 2010年09月22日 20:57
  • 460

<the hacker guide to python>读书笔记

1.Coding style & automated checks And so the Python community, in their vast wisdom, came up with th...
  • pfm685757
  • pfm685757
  • 2015年11月19日 16:04
  • 800

Linux Kernel - A Developer's Guide (如何成为一个Linux内核开发者)

  • swlhmq
  • swlhmq
  • 2014年12月02日 23:57
  • 695

The Linux Kernel Module Programming Guide 2.4 中文版

Table of Contents Foreword 1. 作者声明 2. 版本和注意 3. 感谢 4. 译者注 1. Introduction 1.1. 什么是内核模块? 1.2. 内核模块是如何被...
  • menuconfig
  • menuconfig
  • 2007年09月29日 11:14
  • 2073

kernel hacker’s guide to git

from : This tutorial is a cookbook of recipes getting up and runn...
  • lengyuex
  • lengyuex
  • 2011年03月27日 15:59
  • 718

Road Hackers:自动驾驶平台

数据 原理 开放平台数据10000公里数据,涉及很多数据,自定位、决策、路况分析、POI 和高精地图。一是全景图片数据,二是汽车姿态数据。 关于图片数据,地图采集车采集到的是360度全景数据,但考虑到...
  • c602273091
  • c602273091
  • 2017年01月11日 16:27
  • 1189

Probabilistic Programming and Bayesian Methods for Hackers读书笔记

本文为《Probabilistic Programming and Bayesian Methods for Hackers》读书笔记,网页链接为
  • zc02051126
  • zc02051126
  • 2015年04月25日 22:18
  • 2289

使用 GIT 获得Linux Kernel的代码并查看,追踪历史记录

Linux kernel  的官方 GIT地址是: 可以从这...
  • CaspianSea
  • CaspianSea
  • 2014年05月07日 02:55
  • 11463

uva 11825 黑客的攻击 Hackers' Crackdown 集合dp+我的优化 非常好的好题

题目:点我 题目大意:(黑客的攻击)假设你是一个黑客,侵入了了一个有着n台计算机(编号为0,1,…,n-1)的网络。一共有n种服务,每台计算机都运行着所有的服务。对于每台计算机,你都可以选择一项服...
  • yskyskyer123
  • yskyskyer123
  • 2016年02月05日 16:25
  • 422

Git 克隆Linux kernel

转载至: 到 下载git...
  • robertsong2004
  • robertsong2004
  • 2015年07月15日 09:47
  • 1494
您举报文章:Kernel Hackers' Guide to git