Jim Cheung

Git

Notes

config

$ git config -l
$ git config --unset --global user.email
$ git config --global alias.show-graph 'log --graph --abbrev-commit --pretty=oneline'

internal

print object

$ git cat-file -p [object_hash/prefix]

find out object hash by prefix

$ git rev-parse [object_hash_prefix]

the index

index doesn't contain any file content, it tracks what you want to commit.

$ git log --follow [file]

commit names

relative commit names

since..until

$ git log --pretty=oneline --abbrev=commit master~12..master~10

note, master~12 is not included above

show n line logs

$ git log -n

more stat

$ git log --pretty=short --stat

display object

$ git show master~1

find commits

use git bisect

search log

$ git log -Spattern --pretty=oneline --abbrev-commit [file]

Cookbook

Pull Requests
Fork remote origin

$ git fetch origin

update local branch

$ git checkout master
$ git pull --rebase

Move repo to another host

$ cd localrepo
$ git push --mirror remote/repo.git

Add external repo

$ cd repo # top level
$ git submodule add external/repo.git localfolder
$ git submodule update --init # without --init for regular update

Get changed files list

$ git show --pretty="format:" --name-only ..HEAD|sort|uniq|tail --lines=+2 -

Rebase

Keep your changes locally (not merge to master), use rebase (use it on your own code only, it destroys history) git rebase saves your changes as patches, update to lateset version, then applies patches.

Resources