Git
From Crashcourse Wiki
This is a quick-and-dirty, newbie-level page to getting started with git. For now, I'll just summarize the most common git subcommands for those folks who just want to check out the kernel from its main git repository and examine its contents and attributes in various ways. Additional (and more involved) subsections will follow.
Contents |
Examining your repository
Overview
The git subcommands in this section let you poke around your current clone to examine its commits and other information. We're assuming you're not making any changes yet -- that comes in a later section.
If you have any comments or corrections, drop me a note at rpjday@crashcourse.ca.
status
As long as you haven't made any changes to your clone, checking the status should produce simply:
$ git status # On branch master nothing to commit (working directory clean) $ man git-status
branch
Examine your current branch(es), for which you should see only:
$ git branch * master origin $
If you want a little more detail, try any of the following:
$ git branch -v [verbose] $ git branch -v --abbrev=10 [SHA1 abbreviation length ...] $ git branch -v --no-abbrev [... or not, as the case may be] $ man git-branch
tag
Examine the tag history of your repository, either explicitly or using regular expressions:
$ git tag [all tags] v2.6.11 v2.6.11-tree v2.6.12 v2.6.12-rc2 ... $ git tag -l *-rc1 [only *-rc1 pattern tags] $ git tag -l *2.6.23* [2.6.23-related tags] $ git tag -n 5 [number of annotation lines to display] $ man git-tag
log
First, the default, unadulterated, full log of the repository (during which you can search using the standard "less" search keystrokes):
$ git log
And some potentially useful variations:
$ git log -5 [only that many recent log entries] $ git log -p [show the corresponding patches] $ git log --reverse [reverse order (oldest to newest)] $ git log v2.6.23.. [all entries in a given range]
You can also pick on specific files or directories to examine. This will skip over commits that do not touch the named directories.
$ git log -5 scripts/ $ git log -2 -p Makefile */Makefile $ man git-log
If an argument cound be either a branch or tag name, or a directory name, separate the two with --:
$ git log -- test/
shortlog
A pretty summary of log entries, normally for release announcements:
$ git shortlog -10 [summarise last 10 log entries] $ git shortlog -n -10 [sort by author prolificness] $ git shortlog -s -10 [author summary only] $ git shortlog -n -s Makefile [a practical(?) example]
whatchanged
This is a variation of git log to show the differences introduced by commits. Note well that, by default, you won't see commits that represent only merges unless you ask for them.
$ git whatchanged [full output] $ git whatchanged -m [merge commits as well] $ git whatchanged -5 [last 5 (excluding merge) commits] $ git whatchanged -2 Makefile [just for Makefile] $ git whatchanged -2 -p Makefile [show textual diffs] $ git whatchanged -p v2.6.23.. Makefile [since that tag] $ git whatchanged kernel/ [in that entire subdirectory]
QUESTION: What's the value of the -r option? It doesn't seem to make any difference with any of the examples I've tried.
show
git show can be used to show an arbitrary object, or an older version of a given file:
$ git show HEAD [show the HEAD commit] $ git show HEAD^ [show the previous commit] $ git show v2.6.23 [show that tag info] $ git show v2.6.21:Makefile [show that version of "Makefile"] $ man git-show
Not surprisingly, there's way more to "show" than just the above.
blame
Annotate each line in a given file to see who's responsible for every single line:
$ git blame Makefile $ git blame -L 20,30 Makefile [just that line range] $ git blame v2.6.23.. Makefile [only changes since v2.6.23] $ man git-blame
grep
The git grep utility searches only source files, that is files managed by git. This is a simple way to do a recursive grep that skips over object files and other cruft.
$ git grep some_function $ git grep some_function lib/ include/

