配置文件
/etc/gitconfig | 系统中对所有用户都普遍适用的配置。若使用git config 时用--system 选项,读写的就是这个文件 |
~/.gitconfig | 用户目录下的配置文件只适用于该用户。若使用gitconfig 时用--global 选项,读写的就是这个文件 |
.git/config | 当前项目的git 目录中的配置文件,这里的配置仅仅针对当前项目有效。每一个级别的配置都会覆盖上层的相同配置,所以.git/config 里的配置会覆盖/etc/gitconfig中的同名变量。 |
用户名 | git config --global user.name "John Doe" |
邮箱 | git config --global user.email johndoe@example.com |
默认编辑器 | git config --global core.editor emacs |
差异分析工具 | git config --global merge.tool vimdiff |
查看配置信息 | git config --list |
.gitignore | 忽略某些文件 |
[HTTP] proxy=http://127.0.0.1:1080 | 使用代理 |
常用命令
git init | 当前目录初始化 |
git status | 检查当前文件状态 |
git add | 始跟踪一个新文件 |
git diff | 查看尚未暂存的文件更新了哪些部分 |
git diff --cached | 查看已经暂存的文件更新了哪些部分 |
git commit | 提交更新 |
git rm | 移除文件 |
git rm --cached | 从已跟踪文件清单中移除 |
git mv | 移动文件 |
git log | 查看历史 |
git commit --amend | 修改最后一次提交 |
git reset HEAD | 取消已经暂存的文件 |
git checkout -- file | 恢复到修改前的版本 |
git remote -v | 显示远程地址 |
git remote add name address | 添加运程地址 |
git fetch origin | 从远程仓库抓取数据到本地 |
git push origin master | 推送数据到远程仓库 |
git remote show origin | 查看远程仓库信息 |
git pull | 抓取数据合并到本地 |
git remote rename newname oldname | 修改某个远程仓库的简短名称 |
git remote rm name | 删除远程仓库 |
git push origin :branchname | 删除远程仓库 |
git tag | 列出现有标签 |
git mergetool | 打开冲突合并工具 |
git branch --merged/--no-merged | 查看合并(未合并)到当前分支的分支 |
git branch -d/-D branchname | 删除(强制删除)指定分支 |
git checkout --track origin/branchname | 跟踪远程分支 |
git checkout -b branchname origin/branchname | 跟踪远程分支 |
git clone --bare my_project my_project.git | 导出git纯仓库 |