为了避免重复信息,没有对以下命令进行解释。强烈推荐您阅读 Pro Git 中文版。
基础
git help: 获取 git 命令的帮助信息git init: 创建一个新的 git 仓库,其数据会存放在一个名为.git的目录下git status: 显示当前的仓库状态git add: 添加文件到暂存区git commit: 创建一个新的提交git log: 显示历史日志git log --all --graph --decorate: 可视化历史记录(有向无环图)git diff <filename>: 显示与暂存区文件的差异git diff <revision> <filename>: 显示某个文件两个版本之间的差异git checkout <revision>: 更新 HEAD 和目前的分支
分支和合并
git branch: 显示分支git branch <name>: 创建分支git checkout -b <name>: 创建分支并切换到该分支- 相当于
git branch <name>; git checkout <name> git merge <revision>: 合并到当前分支git mergetool: 使用工具来处理合并冲突git rebase: 将一系列补丁 rebase 为新的基线
远程操作
git remotegit remote add <name> <url>git push <remote> <local branch>:<remote branch>git branch --set-upstream-to=<remote>/<remote branch>git fetchgit pullgit clone
撤销
git commit --amend: 编辑提交的内容或信息git reset HEAD <file>: 恢复暂存的文件git checkout -- <file>: 丢弃修改
高级操作
git configgit clone --depth=1: 浅克隆(shallow clone),不包括完整的版本历史信息git add -p: 交互式暂存git rebase -igit blame: 查看最后修改某行的人git stach: 暂时移除工作目录下的修改内容git bitsect: 通过二分查找搜索历史记录.gitignore: 指定故意不追踪的文件
