1.配置
git config --global user.name "xxx" // 配置用户名
git config --global user.email "xxx@xxx.com" // 配置邮件
2.创建
git init // 初始化本地 git 仓库(新建仓库)
3.本地更改
git status // 查看当前版本状态(是否修改)
git diff // 显示所有未添加至 index 的变更
git diff HEAD // 查看已缓存的与未缓存的所有改动
git add <path> // 将该文件添加到缓存
git commit -m ‘xxx’ // 提交
git commit --amend -m ‘xxx’ // 合并上一次提交(用于反复修改)
git commit -am ‘xxx’ // 将 add 和 commit 合为一步
4.提交历史记录
git log // 显示日志
git show <commit> // 显示某个提交的详细内容
git blame <file> // 在每一行显示 commit 号,提交者,最早提交日期
5.分支机构和标签
git branch // 显示本地分支
git checkout <branch> // 切换分支
git branch <new-branch> // 新建分支
git branch --track <new> <remote> // 创建新分支跟踪远程分支
git branch -d <branch> // 删除本地分支
git tag <tag-name> // 给当前分支打标签
6.合并与衍合
git merge <branch> // 合并分支到当前分支,存在两个
git rebase <branch> // 合并分支到当前分支,存在一个
git rebase --abort // 回到执行 rebase 之前
git rebase --continue // 解决矛盾后继续执行 rebase
git mergetool // 使用 mergetool 解决冲突
git add <resolve-file> // 使用冲突文件解决冲突
git rm <resolved-file>
7.更新和发布
git remote -v // 列出远程分支详细信息
git remote show <remote> // 显示某个分支信息
git remote add <remote> <url> // 添加一个新的远程仓库
git fetch <remote> // 获取远程分支,但不更新本地分支,另需 merge
git pull <remote> <branch> // 获取远程分支,并更新本地分支
git push <remote> <branch> // 推送本地更新到远程分支
git push <remote> --delete <branch> // 删除一个远程分支
git push --tags // 推送本地标签