Git学习
pro git
git命令手册
廖雪峰 gre
Git安装
config
- --system 选项: /etc/gitconfig文件,系统中对所有用户都普遍适用的配置
- --global 选项:~/.gitconfig 文件,用户目录下的配置文件只适用于该用户
- 当前项目Git目录中的配置文件,也就是工作目录中的 .git/config 文件,仅仅针对当前项目有效
- $ git config --list
- $ git config --global user.name "xxx"
- $ git config --global user.email "xxx@qq.com"
- $ git config --global core.editor 文本编辑器
- $ git config --global merge.tool 差异分析工具
SSH
- $ ssh-keygen -t rsa -C "1391621151@qq.com"
创建仓库 repository
- $ git init
- $ git clone ssh://user@domain.com/repo.git
- $ git clone http://domain.com/user/repo.git
状态
本地修改
- $ git add -p <filename>
- $ git add *
- $ git commit -a
- $ git commit -m 'message of this commit'
撤销修改
- $ git checkout -- <filename>
- $ git checkout HEAD <filename>
- $ git reset --hard HEAD
- $ git reset HEAD <filename>
- $ git reset --hard commit_id
- $ git commit --amend 修改最后一次提交
删除
提交历史
- $ git log
- $ git log --oneline
- $ git log --author="username"
- $ git log -p <filename>
- $ git reflog
- log --graph --oneline --decorate
分支 branch
- $ git branch
- $ git branch -r
- $ git branch <new-branchName
- $ git branch --track <new-branchName> <remote-branchName
- $ git checkout <branchNmae>
- $ git checkout -b <new-branchNmae>
- $ git branch -d <branchName>
合并 merge
- $ git merge <other-branch-name>
- $ git merge --no--ff -m "merge commit message" <other-branch-name>
- git merge --abort
隐藏 stash
- $ git stash
- $ git stash list
- $ git stash apply <stash-id>
- $ git stash drop
- $ git stash pop
标签
- $ git tag
- $ show <tag-name v1.0>
- $ git tag <tag-name v1.0>
- $ git tag <tag-name v1.0> <commit--id>
- $ git tag -a <tag-name>
- $ git tag -a <tag-name> -m "version message" <commit--id>
- $ git tag -d <tag-name>
- $ git push origin <tag-name>
- $ git push origin --tags
- $ git tag -d <tag-name>
- $ git push origin :refs/tags/<tag-name>
添加远程库
- $ git remote -v
- $ git remote show <remotename>
- $ git remote add <remoteName> <url>
- $ git remote add origin git@github.com:username/project.git
- $ git push -u origin master
- $ git push origin master
上传到远程库
- $ git push -u origin master
- $ git push origin master
- $ git push origin branchName
- $ git pull
- $ git checkout -b branch-name origin/branch-name
- $ git branch --set-upstream branch-name origin/branch-name
- $ git pull
- $ git push origin master
从远程库克隆
- $ git clone git@github.com:username/project.git
- $ git clone ssh://user@domain.com/repo.git
- $ git clone http://domain.com/user/repo.git
远程同步
- 远程与本地分别进行修改和提交
- git fetch origin 同步远程服务器上的数据到本地
- origin/master和master分别指向一个分支,合并点在上一次同步处
搜索
- $ git grep "xxx"
- $ git grep "xxx" v2.5
忽略特殊文件
- .gitignore
- $ git check ignore
别名
- $ git config --global alias.aliasName gitCommand
- $ git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)
<%an>%Creset' --abbrev-commit"