创建
git clone 仓库地址 克隆仓库
git init 创建新的版本库
本地改变
git status 查看版本库状态
git diff 查看跟踪文件的更改
git add . 添加当前所有更改到暂存库
git add -p <file> 添加一些文件的更改到下一次提交
git commit -a 提交跟踪文件中的所有本地更改
git commit 提交以前阶段的更改
git commit --amend 更改最后一次提交
提交历史
git log 显示所有提交
git log -p <file> 显示特定文件随时间的变化
git blame <file> 谁更改了文件的内容和时间
分支与标签
git branch -av 列出所有现有分支
git checkout <branch> 切换分支
git branch <new-branch> 根据当前分支去创建一个新的分支
git checkout --track <remote/branch> 基于远程分支创建一个新的跟踪分支
git branch -d <branch> 删除分支
git tag <tag-name> 用标签标记当前提交
更新与发布
git remote -v 查看当前分支的远程管理库
git remote show <remote> 查看 的信息
git remote add <shortname> <url> 在 处添加一个名为 的存储库
git fetch <remote> 从另一个存储库下载对象和引用
git pull <remote> <branch> 从另一个存储库或本地分支获取并与其集成
git push <remote> <branch> 更新远程引用以及关联的对象
git push --tags 发布标签
合并与回退
git merge <branch> 合并分支到当前分支
git rebase <branch> 重新申请提交另一个分支
git rebase --abort 中止 rebase 操作并将 HEAD 重置为原始分支
git rebase --continue 解决了合并冲突后重新启动重新绑定过程
git mergetool 使用您配置的合并工具解决冲突
使用编辑器手动解决冲突并在解决标记文件后解决
git add <resolved-file>
git rm <resolved-file>
撤销/回滚
git reset --hard HEAD 丢弃工作目录中的所有本地更改
git checkout HEAD <file> 放弃特定文件中的本地更改
git revert <commit> 回滚提交
git reset --hard <commit> 将您的HEAD指针重置为先前的提交,并丢弃此后的所有更改
git reset <commit> 将您的HEAD指针重置为先前的提交,将所有更改保留为非暂存更改
git reset --keep <commit> 将您的HEAD指针重置为先前的提交,保留未提交的本地更改