
1. 常用
$ git remote add origin git@github.com:yeszao/dofiler.git $ git pull origin master $ git push origin master $ git fetch origin $ git branch $ git checkout master $ git checkout -b dev $ git commit -m "first version" $ git status $ git log $ git config --global core.editor vim $ git config core.ignorecase false $ git config --global user.name "YOUR NAME" $ git config --global user.email "YOUR EMAIL ADDRESS"
2. 别名 alias
$ git config --global alias.br="branch" # 创建/查看本地分支$ git config --global alias.co="checkout" # 切换分支$ git config --global alias.cb="checkout -b" # 创建并切换到新分支$ git config --global alias.cm="commit -m" # 提交$ git config --global alias.st="status" # 查看状态$ git config --global alias.pullm="pull origin master" # 拉取分支$ git config --global alias.pushm="push origin master" # 提交分支$ git config --global alias.log="git log --oneline --graph --decorate --color=always" # 单行、分颜色显示记录$ git config --global alias.logg="git log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative" # 复杂显示
3. 创建版本库
$ git clone <url> $ git init
4. 修改和提交
$ git status $ git diff $ git add . $ git add <file> $ git mv <old> <new> $ git rm <file> $ git rm --cached <file> $ git commit -m “commit message” $ git commit --amend
5. 查看历史
$ git log $ git log -p <file> $ git blame <file>
6. 撤销
$ git reset --hard HEAD $ git reset --hard <version> $ git checkout HEAD <file> $ git checkout -- <file> $ git revert <commit>
7. 分支与标签
$ git branch $ git checkout <branch/tag> $ git branch <new-branch> $ git branch -d <branch> $ git tag $ git tag <tagname> $ git tag -a "v1.0" -m "一些说明" $ git tag -d <tagname> $ git checkout dev $ git cherry-pick 62ecb3
8. 合并与衍合
$ git merge <branch> $ git merge --abort $ git merge dev -Xtheirs $ git rebase <branch>
9. 远程操作
$ git remote -v $ git remote show <remote> $ git remote add <remote> <url> $ git remote remove <remote> $ git fetch <remote> $ git pull <remote> <branch> $ git push <remote> <branch> $ git push <remote> :<branch/tag-name> $ git push --tags
10. 打包
$ git archive --format=zip --output ../file.zip master # 将master分支打包成file.zip文件,保存在上一级目录$ git archive --format=zip --output ../v1.2.zip v1.2 # 打包v1.2标签的文件,保存在上一级目录v1.2.zip文件中$ git archive --format=zip v1.2 > ../v1.2.zip # 作用同上一条命令
11. 全局和局部配置
全局配置保存在:$Home/.gitconfig本地仓库配置保存在:.git/config
12. 远程与本地合并
$ git init $ git add . $ git commit -m "add local source" $ git pull origin master $ git merge master $ git push -u origin master
