Friday, May 15, 2015

Git Tips

Shorten your Git commands - Alias

git config --global alias.[name] "command"

Examples

git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.cob "checkout -b"
git config --global alias.back "checkout master"
git config --global alias.cof "checkout --"
git config --global alias.pl "pull --rebase origin master"
git config --global alias.plf "!git stash && git pl && git stash pop" # ! means runing the command as shell command
git config --global alias.lo "log --graph --oneline"
git config --global alias.l "log --pretty=format:'%C(yellow)%h %C(red)%ad %C(green)%d %C(reset)%s [%C(blue)%an]' --date=short --graph"

A better git log tool - tig

TIG

install

brew install tig

Get commit from other branchs - cherry-pick

cherry-pick
git cherry-pick [CommitID]
git cherry-pick --no-commit [CommitID] # 把commit内容放到本地的cache里面
You can test cherry-pick on GitStudy.

Find commit which you force deleted - reflog

Git won’t really delete any commit even you use git reset --hard HEAD^. You can get it back by reflog.

No comments:

Post a Comment