Git使用小技巧
记录一下平时使用git用到的小知识点。
checkout
git checkout –track origin/xxx
update
git remote update
set new remote url
git remote set-url origin ${git_url}
add origin if not exists
git remote add origin ${git_url}
git push -u origin –all # pushes up the repo and its refs for the first time
git push -u origin –tags # pushes up any tags
branch
rename branch
git branch -m old new
delete remote branch
git push –delete origin ${brahch_name}
delele local which doesn’t contains remote
git fetch -p
pick commit to push
git push origin {commit-id}:{branch}
git log
git log -n #显示n条log
git log –graph #图像方式显示log
git log –pretty=raw #show logs with all parent
git log –pretty=oneline #简化log输出方式,只显示commit id + commit comment
git reflog
用来记录所有操作的log信息。如果你发现找不到commit记录了,那么你可以用这个来找回commit号。为什么能找到呢?因为它记录的是操作日志。
^ or ~
^ 表示当前HEAD的parent。 HEAD可能会有N个Parent,指定^n表示当前HEAD的第几个parent。
HEAD^等同于^1
~ 表示当前HEAD的parent的parent。HEAD~2表示给予当前HEAD的往前移动2个parent。
HEAD~等同于HEAD~1
HEAD~2=HEAD^^=HEAD^1^1 表示当前parent的parent
git diff
git diff 查看工作区跟版本库的区别
git diff –cache 查看暂存区跟版本库的区别
fetch diff between 2 commits
git diff {commit1}(not include) {commit2}
git config
private
git config user.name ram
git config user.email ram@yun.io
globle
git config –global user.name ram
git config –global user.email ram@yun.io
show all configs
git config –list
Oter
- No tracked branch configured for branch ${brahch_name} in Git repository ${path}
To make your branch track a remote branch call
git branch –set-upstream ${brahch_name} origin/${brahch_name}
T.B.C.
By @hyongbai 共1461个字 本文链接 http://yourbay.me/all-about-tech/2017/07/31/git-tips/