常用命令
新建仓库
git init
git status
git add [file1] [file2] ...
git commit -m "message"
git remote add origin git@github.com:yanhaijing/test.git
git remote set-url origin git@github.com:yanhaijing/test.git
git push -u origin master 复制代码
从现有仓库克隆
git clone git://github.com/yanhaijing/data.js.git
git clone git://github.com/schacon/grit.git mypro 复制代码
本地操作
git add *
git add -p
rm *&git rm *
git rm -f *
git rm --cached *
git mv file_from file_to
git log
git commit
git commit [file1] [file2] ...
git commit -m 'message'
git commit -a
git commit --amend
git commit -v
git reset HEAD *
git reset --mixed HEAD *
git reset --soft HEAD *
git reset --hard HEAD *
git revert HEAD
git revert HEAD~
git revert commit
git checkout -- file
git diff file
git diff --stat
git diff
git diff --cached
git diff HEAD
git diff branch
git diff branch1 branch2
git diff commit commit
git log
git stash
git stash list
git stash apply
git stash drop
git stash pop
git stash apply stash@{0} 复制代码
分支操作
git branch
git branch -r
git branch -a
git branch test
git branch -m old new
git branch -d test
git branch -D test
git checkout test
git checkout -b test
git checkout -b test dev
git merge test
git rebase master
git rebase --interactive
git rebase --continue
git rebase --skip
git rebase --abort 复制代码
远端操作
git fetch origin remotebranch[:localbranch]
git merge origin/branch
git pull origin remotebranch:localbranch
git push origin branch
git push origin localbranch:remotebranch
git push origin :remotebranch
git push origin remotebranch --delete
git branch -dr branch 复制代码
源操作
git remote add origin1 git@github.com:yanhaijing/data.js.git
git remote
git remote -v
git remote rename origin1 origin2
git remote rm origin
git remote show origin 复制代码
标签操作
git tag
git tag v0.1 [branch|commit]
git tag -a v0.1 -m 'my version 1.4'
git checkout tagname
git push origin v1.5
git push origin --tags 复制代码
常用配置
更改git默认的用户名和邮箱
git config --global user.name "NewName"
git config --global user.email "NewEmail"
git config --global user.name
git config --global user.email
git config --list 复制代码
常用操作命令简写
g -> git
gst -> git status
gd -> git diff
gdc -> git diff --cached
gdv -> git diff -w "$@" | view -
gl -> git pull
gup -> git pull --rebase
gp -> git push
gco -> git checkout
gr -> git remote
grv -> git remote -v
gb -> git branch
gba -> git branch -a
gcl -> git config --list
ga -> git add
gm -> git merge复制代码
参考资料
- Git简易指南:www.bootcss.com/p/git-guide…
- codeschool try git:try.github.io/levels/1/ch…
- 30 天精通 Git 版本控管:github.com/doggy8088/L…
- Pro git 中文版:git.oschina.net/progit/
- git 参考手册:gitref.org/zh/index.ht…
- 聊雪峰 使用github:www.liaoxuefeng.com/wiki/001373…
- 图解gitmarklodato.github.io/visual-git-…
- git book:git-scm.com/book/zh/v2