设为首页 收藏本站
查看: 789|回复: 0

[经验分享] kernel hacker’s guide to git

[复制链接]

尚未签到

发表于 2018-9-18 09:33:17 | 显示全部楼层 |阅读模式
  Further reading
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 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>  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 Tasks
Update 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 -fCheck 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 from git 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 HEADObtain summary of all changes in working dir
$ git statusList 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.cBranches
List all branches
$ git branchMake desired branch current in working directory
$ git checkout $branchCreate a new branch, and make it current
$ git checkout -b my-new-branch-name masterExamine 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 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)
  or rather than full changeset descriptions, obtain a one-line summary of each changes:
$ git shortlog master..HEADMerge 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 merge A# merge A into M
  
$ git merge B# merge B into M
Misc. Debris
Optimize 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 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
  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 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.
Tag a particular 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 do a lot more 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.



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-589681-1-1.html 上篇帖子: SVN版本库迁移到Git工具SubGit 下篇帖子: 在UBUNTU 10上搭建GIT服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表