Kernel hacker's guide to git

Source: Internet
Author: User

From: http://linux.yyz.us/git-howto.html

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.

Table of Contents
  • Getting Started
    • Installing git
    • First kernel tree download
  • Basic tasks
    • Download Remote Tree updates
    • Undo All working dir modifications
    • Undo recent commits
    • Check in changes
    • Generate diff of working dir changes
    • Generate Summary of working dir changes
    • List all Changeset descriptions
    • List all Changeset descriptions belonging to a specific file
  • Branches
    • List all branches
    • Switch working dir to new branch
    • Create new branch
    • List current Branch
    • Diff against master branch
    • List changes present only on local branch
    • Merge changes from one branch into another
  • Misc. debris
    • Check out an older kernel version
    • Apply mailbox full of patches
    • Download tags periodically
    • Create a tag
  • Further reading
    Getting StartedInstalling git

    Git requires bootstrapping, since you must have git installed in order to check outGit. git(GIT repository), andLinux-2.6.git(Kernel repository). You may find that your distribution already provides a usable version of git. If so, try that first.

    • Fedora 7 and later: The git-core package is available through the standard package repositories. Fedora Core 3 through 6: git-core package is in Fedora Extras.

      Yum install Git-core

    If your distro does not package git, you may download the latest stable release from:
    Http://www.kernel.org/pub/software/scm/git/

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

    Install tarball:

    unpack && make prefix=/usr/local && 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: // git.kernel.org/pub/scm/git/git.git

    Download a linux kernel tree for the very first time
    $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux-2.6

    NOTE: The kernel tree is very large. This constitutes downloading just over 300 megabytes of compressed data (as of Jun 2008 ).

    Basic TasksUpdate local kernel tree to latest 2.6.x upstream ("fast-forward merge ")
    $ cd linux-2.6$ git pull git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

    Or more simply, to pull from the location from which you cloned:

    $ cd linux-2.6$ git pull

    To pull from the origin repository from which you originally cloned the tree.

    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
    Undo recent commits:

    Sometimes you have made a few commits, or just pulled a change, and simply want those commits to go away.

    $ cd my-kernel-tree-2.6$ git reset HEAD~2# make last 2 commits disappear

    Will "disappear" the top two commits.Do not do this, if anyone has downloaded a tree containing the commits you just eliminated.

    Note that this is quite different fromGit revert, Which applies a reversed patch as an additional commit.

    List all changes in working dir, in diff format.

    Display changes since last 'git add' or 'git rm ':

    $ git diff

    Display changes since last commit:

    $ git diff HEAD
    Obtain summary of all changes in working dir
    $ git status
    List all Changeset descriptions
    $ git log

    The 'git log' option "-p" shows diffs in addition to changeset text. The option "-- stat" shows the diffstat in addition to the changeset text.

    List all changesets belonging to a specific file

    (In this case, net/ieee80211/ieee80211_module.c)

    $ git log net/ieee80211/ieee80211_module.c
    Brancheslist 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 status

    ('Git branch' also shows you the current branch, using a "*" to indicate this)

    Obtain a diff between current branch, and Master Branch

    In most treesWith branches,. Git/refs/heads/masterContains 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 equivalentGit diff HEAD, When used with HEAD branch)

    Obtain a list of changes between current branch, and Master Branch
    $ git log master..HEAD

    (This is equivalentGit log, When used with HEAD)

    Or rather than full changeset descriptions, obtain a one-line summary of each changes:

    $ git shortlog master..HEAD
    Merge changes from one branch into another

    Let us suppose that you do work on branchAAnd branchB, And after work on those two branches is complete, you merge the work into mainline branchM.

    $ git checkout M# switch to branch M$ git merge A# merge A into M$ git merge B# merge B into M
    Misc. debrisoptimize Your repository

    Git is heavily optimized for fast storage and retrieval on a per-command basis. however, over a long period of time, it can be useful to perform further optimizations, including packing all git objects into single "packfile" for fast retrieval and less wasted disk space.

    $ cd my-kernel-tree-2.6$ git gc

    Will optimize your repository. You don't need to run this frequently-git is quite fast even without it. See the 'git gc 'man page for more details.

    Check out an older kernel version
    $ cd my-kernel-tree-2.6$ git checkout -b tmp v2.6.22

    This creates a temporary branch 'tmp ', with the contents of kernel version 2.6.22.

    Apply all patches in a Berkeley mbox-Format File

    First, make sure thatToolsSubdirectory of the git-core repository is in your PATH.

    $ cd my-kernel-tree-2.6$ git am --utf8 --signoff /path/to/mbox

    The file/Path/to/mboxIs a Berkeley mbox file, containing one or more patches to be committed to the git repository.-- SignoffOption indicates that 'git am' should append

    Signed-off-by: Your name <your@email.com>

    Line that is common to almost all kernel submissions. The name and email address are taken from the GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL environment variables (I recommend setting these in your. bash_profile or similar file ).

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

    Git pullOnly downloads sha1-indexed object data, and the requested remote head. This misses updates to. Git/refs/tags/And. Git/refs/heads/Directories. For tags, runGit fetch -- tags $ URL.

    Tag a participant commit.

    For your own repositories, you may wish to give interesting or significant commits a name, known as a tag. the Linux kernel uses tags to for each kernel version: "v2.6.21", "v2.6.22", etc.

    $ cd my-kernel-tree-2.6$ git tag my-tag

    Creates a new tag named "My-tag", based on the current commit. You can doLotMore with tagging, including GPG-signing, so read the man page for more details.

    Further reading

    Another good introduction is the official git tutorial, followed by the more in-depth git man page documentation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.