haohaio
努力学习,艰苦奋斗
写写代码,记记笔记
配置
$ git config --global user.name "username"
$ git config --global user.email "email"
$ git config --global -l
|
仓库
$ git init
$ git clone url (gcl)
$ git remote -v (grv)
$ git remote add name url
$ git remote remove name
|
基本命令
$ git add .
$ git add dir/file
|
$ git add .
$ git add -A (gaa)
|
$ git commit -m (gcmsg)
$ git commit -a -m (gcam)
$ git commit --amend
|
$ git reset
$ git reset HEAD^(HEAD~1)
|
$ git checkout file(dir)
$ git checkout d928a3
|
$ git clean -f
$ git clean -fd
$ git clean -nfd
|
$ git diff (gd)
$ git diff –-cached (gdca)
$ git diff HEAD
|
$ git log
$ git log -p
$ git log --stat
$ git log --pretty=oneline
$ git log -3
$ git log --since="24 hours"
$ git log file
$ git log --grep="fixbug"
$ git log --author="yuanfang"
|
会记录所有HEAD的历史,也就是说当你做 reset,checkout等操作的时候,这些操作会被记录在reflog中。
查看“丢失的”对象们,比如因reset而看不到的commit
$ git show
$ git show d928a3
|
$ git blame file
$ git blame -L 50,60 file
|
$ git stash
$ git stash pop
$ git stash list
$ git stash list -p
$ git stash apply stash@{1}
$ git stash clear
$ git stash drop stash@{1}
|
分支
$ git branch
$ git branch -r
$ git branch -a
$ git branch new_branch
$ git checkout new_branch
$ git branch -d new_branch
$ git push origin new_branch
$ git push origin :new_branch
|
- git merge & git rebase & git cherry-pick
$ git merge master
$ git rebase master
$ git cherry-pick commit-id
|
标签
$ git tag
$ git tag new_tag
$ git tag -d new_tag
$ git push origin new_tag
$ git push origin --tags
$ git push origin -d tag new_tag $ git push origin :refs/tags/new_tag
$ git fetch origin
|
补丁
$ git diff > .patch
$ patch -p1 < .patch
|
.gitignore
*.a !lib.a /TODO build/ doc/*.txt
|
- .gitignore文件发现却没有生效时( .gitignore只能忽略那些原来没有被track的文件)
$ git rm -r --cached . $ git add . $ git commit -m 'update .gitignore'
|
$ git log --pretty=oneline --author='username' | wc -l
|
本文代表个人观点,内容仅供参考。若有不恰当之处,望不吝赐教!