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.
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.
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
$ 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).
$ 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.
$ git checkout -f
# 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
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 from git revert, which applies a reversed patch as an additional commit.
Display changes since last 'git add' or 'git rm':
$ git diff
Display changes since last commit:
$ git diff HEAD
$ git status
$ 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.
$ git log net/ieee80211/ieee80211_module.c
$ git branch
$ git checkout $branch
$ git checkout -b my-new-branch-name master
$ git status
('git branch' also shows you the current branch, using a "*" to indicate this)
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)
$ git log master..HEAD
(this is equivalent to git log, when used with HEAD)
or rather than full changeset descriptions, obtain a one-line summary of each changes:
$ git shortlog master..HEAD
$ git checkout M # switch to branch M $ git merge A # merge A into M $ git merge B # merge B into M
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.
$ 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.
First, make sure that the tools subdirectory 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/mbox is a Berkeley mbox file, containing one or more patches to be committed to the git repository. The --signoff option indicates that 'git am' should append the
Signed-off-by: Your Name <[email protected]>
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).
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 fetch --tags $URL.
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 do a lot more with tagging, including GPG-signing, so read the man page for more details.
Another good introduction is the official git tutorial, followed by the more in-depth git man page documentation.