Git配置
git config --global user.name "storm"
git config --global user.email "stormzhang.dev@gmail.com"
git config --global color.ui true
git config --global alias.co checkout # 别名
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global core.editor "vim" # 设置Editor使用vim
git config --global core.quotepath false # 设置显示中文文件名
用户的git配置文件~/.gitconfig
Git常用命令
git help <command> # 显示command的help
git show
git show $id
git co
git co .
git add <file>
git add .
git rm <file>
git rm <file>
git reset <file>
git reset
git reset
git ci <file>
git ci .
git ci -a
git ci -am "some comments"
git ci
git revert <$id>
git revert HEAD
git diff <file>
git diff
git diff <$id1> <$id2>
git diff <branch1>..<branch2>
git diff --staged
git diff --cached
git diff --stat
git log
git log <file>
git log -p <file>
git log -p -2
- tig
Mac上可以使用tig代替diff和log,brew install tig
Git 本地分支管理
git br -r
git br <new_branch>
git br -v
git br --merged
git br --no-merged
git co <branch>
git co -b <new_branch>
git co -b <new_branch> <branch>
git co $id
git co $id -b <new_branch>
git br -d <branch>
git br -D <branch>
git merge <branch>
git merge origin/master
git rebase master <branch>
git co <branch> && git rebase master && git co master && git merge <branch>
git diff > ../sync.patch # 生成补丁
git apply ../sync.patch # 打补丁
git apply --check ../sync.patch # 测试补丁能否成功
git stash
git stash list
git stash apply
git stash drop
git stash clear
git pull
git pull --no-ff
git fetch origin
git merge origin/master
git co --track origin/branch
git co -b <local_branch> origin/<remote_branch>
git push
git push origin master
git push -u origin master
git push origin <local_branch>
git push origin <local_branch>:<remote_branch>
git push origin :<remote_branch>
git remote -v
git remote show origin
git remote add origin git@github:stormzhang/demo.git
git remote set-url origin git@github.com:stormzhang/demo.git
git clone --bare robbin_site robbin_site.git # 用带版本的项目创建纯版本仓库
scp -r my_project.git git@git.csdn.net:~ # 将纯仓库上传到服务器上
mkdir robbin_site.git && cd robbin_site.git && git --bare init # 在服务器创建纯仓库
git remote add origin git@github.com:robbin/robbin_site.git # 设置远程仓库地址
git push -u origin master # 客户端首次提交
git push -u origin develop # 首次将本地develop分支提交到远程develop分支,并且track
git remote set-head origin master # 设置远程仓库的HEAD指向master分支
git branch --set-upstream master origin/master
git branch --set-upstream develop origin/develop