声明:资料来源互联网
安装
配置
1 2 3 4 5 git config -e [--global] git config --global user.name yanhaijing git config --global user.email yanhaijing@yeah.net git config --list git help config
1 git config --global core.autocrlf input
1 2 ssh-keygen -t rsa -C yanhaijing@yeah.net ssh -T git@github.com
配置别名,git的命令没有自动完成功能,有点坑哈,别名派上了用场
1 2 3 4 git config --global alias.st status git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit
新建仓库
1 2 3 4 5 6 git init git status git add [file1] [file2] ... git commit -m "message" git remote add origin git@github.com:yanhaijing/test.git git push -u origin master
从现有仓库克隆
1 2 git clone git://github.com/yanhaijing/data.js.git git clone git://github.com/schacon/grit.git mypro
本地
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 git add * git add -u [path] 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 reset -- files git revert HEAD git revert HEAD~ git revert commit git checkout -- file git checkout branch|tag|commit -- file_name git checkout -- . 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 log --pretty=oneline git log --graph git log --abbrev-commit git log -num git log --stat git log --follow [file] git log -p [file] git stash git stash list git stash apply git stash drop git stash pop git stash apply stash@{0}
分支
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 git branch git branch -r git branch -a git branch -v git branch --merge git branch --no-merge git branch test git branch branch [branch|commit|tag] git branch --track branch remote-branch git branch -m old new git branch -d test git branch -D test git branch --set -upstream dev origin/dev git checkout test git checkout -b test git checkout -b test dev git merge test git merge --squash test git cherry-pick commit git cherry-pick -n commit git rebase master git rebase --onto master 169a6 git rebase --interactive git rebase --continue git rebase --skip git rebase --abort
远端
1 2 3 4 5 6 7 8 9 10 11 12 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 checkout -b [--track] test origin/dev
源
git是一个分布式代码管理工具,所以可以支持多个仓库,在git里,服务器上的仓库在本地称之为remote。
个人开发时,多源用的可能不多,但多源其实非常有用。
1 2 3 4 5 6 7 8 9 10 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
标签
当开发到一定阶段时,给程序打标签是非常棒的功能。
1 2 3 4 5 6 7 8 9 10 11 12 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 tag -d v0.1 git push origin :refs/tags/v0.1