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
- four object types: blob, tree, commit, tag
- git tracks content(sha1), not diff/filename
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.
- tracking logs on [file]
$ git log --follow [file]
- ignore *.ext files but include a particular one: add
*.ext
to root level.gitignore
,!filename.ext
to.gitignore
under paticular directory
commit names
relative commit names
master^1
: first parentmaster^2
: second parentmaster~1
: first parentmaster~2
: first grandparent
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.