Posted By

lfatr on 02/16/10


Tagged

git github


Versions (?)

KERNEL HACKERS' GUIDE TO GIT


 / Published in: Groovy
 

Posted it here because his website disappeared.

  1. Kernel Hackers' Guide to git
  2. Menu:
  3.  
  4. * Serial ATA
  5. * IPv6
  6. * DNS
  7. * Current projects
  8.  
  9. This tutorial is a cookbook of recipes getting up and running with Linus's source code
  10. management (SCM) software, "git." Its targetted mainly at Linux kernel hackers, though
  11. others may find it useful.
  12. Table of Contents
  13.  
  14. * Getting Started
  15. o Installing git
  16. o First kernel tree download
  17. * Basic tasks
  18. o Download remote tree updates
  19. o Undo all working dir modifications
  20. o Undo recent commits
  21. o Check in changes
  22. o Generate diff of working dir changes
  23. o Generate summary of working dir changes
  24. o List all changeset descriptions
  25. o List all changeset descriptions belonging to a specific file
  26. * Branches
  27. o List all branches
  28. o Switch working dir to new branch
  29. o Create new branch
  30. o List current branch
  31. o Diff against master branch
  32. o List changes present only on local branch
  33. o Merge changes from one branch into another
  34. * Misc. debris
  35. o Check out an older kernel version
  36. o Apply mailbox full of patches
  37. o Download tags periodically
  38. o Create a tag
  39. * Further reading
  40.  
  41. Getting Started
  42. Installing git
  43.  
  44. git requires bootstrapping, since you must have git installed in order to check out git.git
  45. (git repository), and linux-2.6.git (kernel repository). You may find that your distribution
  46. already provides a usable version of git. If so, try that first.
  47.  
  48. * Fedora 7 and later: The git-core package is available through the standard package
  49. repositories. Fedora Core 3 through 6: git-core package is in Fedora Extras.
  50.  
  51. yum install git-core
  52.  
  53. If your distro does not package git, you may download the latest stable release from:
  54. http://www.kernel.org/pub/software/scm/git/
  55.  
  56. tarball build-deps: zlib, libcurl, libcrypto (openssl)
  57.  
  58. install tarball:
  59.  
  60. unpack && make prefix=/usr/local && sudo make prefix=/usr/local install
  61.  
  62. After reading the rest of this document, come back and update your copy of git to the
  63. latest: git://git.kernel.org/pub/scm/git/git.git
  64. Download a linux kernel tree for the very first time
  65.  
  66. $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux-2.6
  67.  
  68. NOTE: The kernel tree is very large. This constitutes downloading just over 300 megabytes of
  69. compressed data (as of Jun 2008).
  70. Basic Tasks
  71. Update local kernel tree to latest 2.6.x upstream ("fast-forward merge")
  72.  
  73. $ cd linux-2.6
  74. $ git pull git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
  75.  
  76. or more simply, to pull from the location from which you cloned:
  77.  
  78. $ cd linux-2.6
  79. $ git pull
  80.  
  81. to pull from the origin repository from which you originally cloned the tree.
  82. Undo all local modifications:
  83.  
  84. $ git checkout -f
  85.  
  86. Check in your own modifications (e.g. do some hacking, or apply a patch)
  87.  
  88. # go to repository
  89. $ cd linux-2.6
  90.  
  91. # make some modifications
  92. $ vi drivers/net/sk98lin/skdim.c
  93.  
  94. # NOTE: Run 'git add' and 'git rm' if adding or removing files.
  95.  
  96. # check in all modifications
  97. $ git commit -a
  98.  
  99. Undo recent commits:
  100.  
  101. Sometimes you have made a few commits, or just pulled a change, and simply want those
  102. commits to go away.
  103.  
  104. $ cd my-kernel-tree-2.6
  105. $ git reset HEAD~2 # make last 2 commits disappear
  106.  
  107. will "disappear" the top two commits. DO NOT do this, if anyone has downloaded a tree
  108. containing the commits you just eliminated.
  109.  
  110. Note that this is quite different from git revert, which applies a reversed patch as an
  111. additional commit.
  112. List all changes in working dir, in diff format.
  113.  
  114. Display changes since last 'git add' or 'git rm':
  115.  
  116. $ git diff
  117.  
  118. Display changes since last commit:
  119.  
  120. $ git diff HEAD
  121.  
  122. Obtain summary of all changes in working dir
  123.  
  124. $ git status
  125.  
  126. List all changeset descriptions
  127.  
  128. $ git log
  129.  
  130. The 'git log' option "-p" shows diffs in addition to changeset text. The option "--stat" shows the diffstat in addition to the changeset text.
  131. List all changesets belonging to a specific file
  132. (in this case, net/ieee80211/ieee80211_module.c)
  133.  
  134. $ git log net/ieee80211/ieee80211_module.c
  135.  
  136. Branches
  137. List all branches
  138.  
  139. $ git branch
  140.  
  141. Make desired branch current in working directory
  142.  
  143. $ git checkout $branch
  144.  
  145. Create a new branch, and make it current
  146.  
  147. $ git checkout -b my-new-branch-name master
  148.  
  149. Examine which branch is current
  150.  
  151. $ git status
  152.  
  153. ('git branch' also shows you the current branch, using a "*" to indicate this)
  154. Obtain a diff between current branch, and master branch
  155.  
  156. In most trees with branches, .git/refs/heads/master contains the current 'vanilla' upstream
  157. tree, for easy diffing and merging. (in trees without branches, 'master' simply contains
  158. your latest changes)
  159.  
  160. $ git diff master..HEAD
  161.  
  162. (this is equivalent to git diff HEAD, when used with HEAD branch)
  163. Obtain a list of changes between current branch, and master branch
  164.  
  165. $ git log master..HEAD
  166.  
  167. (this is equivalent to git log, when used with HEAD)
  168. or rather than full changeset descriptions, obtain a one-line summary of each changes:
  169.  
  170. $ git shortlog master..HEAD
  171.  
  172. Merge changes from one branch into another
  173. Let us suppose that you do work on branch A and branch B, and after work on those two
  174. branches is complete, you merge the work into mainline branch M.
  175.  
  176. $ git checkout M # switch to branch M
  177. $ git merge A # merge A into M
  178. $ git merge B # merge B into M
  179.  
  180. Misc. Debris
  181. Optimize your repository
  182.  
  183. git is heavily optimized for fast storage and retrieval on a per-command basis. However,
  184. over a long period of time, it can be useful to perform further optimizations, including
  185. packing all git objects into single "packfile" for fast retrieval and less wasted disk space.
  186.  
  187. $ cd my-kernel-tree-2.6
  188. $ git gc
  189.  
  190. will optimize your repository. You don't need to run this frequently รข git is quite fast
  191. even without it. See the 'git gc' man page for more details.
  192. Check out an older kernel version
  193.  
  194. $ cd my-kernel-tree-2.6
  195. $ git checkout -b tmp v2.6.22
  196.  
  197. This creates a temporary branch 'tmp', with the contents of kernel version 2.6.22.
  198. Apply all patches in a Berkeley mbox-format file
  199.  
  200. First, make sure that the tools subdirectory of the git-core repository is in your PATH.
  201.  
  202. $ cd my-kernel-tree-2.6
  203. $ git am --utf8 --signoff /path/to/mbox
  204.  
  205. The file /path/to/mbox is a Berkeley mbox file, containing one or more patches to be
  206. committed to the git repository. The --signoff option indicates that 'git am' should append
  207. the
  208.  
  209. Signed-off-by: Your Name <[email protected]>
  210.  
  211. line that is common to almost all kernel submissions. The name and email address are taken
  212. from the GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL environment variables (I recommend
  213. setting these in your .bash_profile or similar file).
  214. Don't forget to download tags from time to time.
  215.  
  216. git pull only downloads sha1-indexed object data, and the requested remote head. This misses
  217. updates to the .git/refs/tags/ and .git/refs/heads/ directories. For tags, run git fetch
  218. --tags $URL.
  219. Tag a particular commit.
  220.  
  221. For your own repositories, you may wish to give interesting or significant commits a name,
  222. known as a tag. The Linux kernel uses tags to for each kernel version: "v2.6.21", "v2.6.22",
  223. etc.
  224.  
  225. $ cd my-kernel-tree-2.6
  226. $ git tag my-tag
  227.  
  228. creates a new tag named "my-tag", based on the current commit. You can do a lot more with
  229. tagging, including GPG-signing, so read the man page for more details.
  230. Further reading
  231.  
  232. Another good introduction is the official git tutorial, followed by the more in-depth git
  233. man page documentation.

Report this snippet  

You need to login to post a comment.