命令 | 解释 |
git init | 初始化git仓库 |
git add <file> | 添加工作区特定文件到暂存区 |
git add . | 添加工作区所有文件到暂存区 |
git commit -m <message> | 提交暂存区所有文件到本地库 |
git status | 查看工作区状态 |
git diff | 查看工作区修改内容,与暂存区的不同 |
git checkout -- <file> | 恢复工作区使与暂存区相同,即撤销工作区的修改 |
git reset <commitId> | 恢复暂存区使与本地库相同,即撤销暂存区的修改,HEAD表示当前提交,HEAD^表示上一次提交,HEAD^^表示上上次提交,HEAD~100表示前一百次提交,次数太多使用commitId值 |
git reset <commitId> <file> | 恢复暂存区的指定文件使与本地库相同 |
git reset --hard <commitId> | 恢复暂存区与工作区使与本地库相同,即撤销暂存区与工作区的修改 |
git log | 查看提交历史 |
git reflog | 查看命令历史 |
git rm <file> | 删除指定文件 |
git remote add origin <url> | 关联git远程库 |
git remote | 查看远程库信息 |
git remote -v | 查看远程库的详细信息 |
git push <-u> origin master | 推送master分支到远程master分支,第一次需添加-u建立与远程master分支的连接 |
git branch --set-upstream-to <branchName> origin/<branchName> | 指定本地分支与远程分支建立连接 |
git pull | 抓取远程库信息,使本地与远程库信息一致 |
git clone <url> | 从远程克隆一个仓库到本地 |
git branch | 查看所有分支,当前分支前标注*号 |
git branch <branchName> | 创建分支 |
git checkout <branchName> | 切换分支 |
git checkout -b <branchName> | 创建并切换分支,相当于以上两个命令 |
git checkout -b <branchName> origin/<branchName> | 创建并合并分支,与远程的分支建立连接 |
git merge <branchName> | 将分支合并到当前分支 |
git merge --no-ff -m “<message>” <branchName> | 不使用Fast forward模式合并分支 |
git branch -d <branchName> | 删除分支 |
git branch -D <branchName> | 强制删除未合并的分支 |
git log --graph | 查看分支合并图 |
git stash | 保存工作现场 |
git stash list | 查看保存的工作现场 |
git stash apply | 恢复但不删除保存的工作现场 |
git stash drop | 删除保存的工作现场 |
git stash pop | 恢复并删除保存的工作现场 |
git stash apply <stashId> | 恢复指定的工作现场 |
git rebase | 将push的分叉提交切换顺序整理成一条直线 |
git tag <tagName> | 打标签,默认为HEAD |
git tag | 查看所有标签 |
git tag <tagName> <commitId> | 对指定的提交打标签 |
git show <tagName> | 查看标签信息 |
git tag -a <tagName> -m "<message>" <commitId> | 创建带说明的标签 |
git tag -d <tagName> | 删除本地标签 |
git push origin <tagName> | 推送指定标签到远程 |
git push origin --tags | 推送所有标签到远程 |
git push origin :refs/tags/<tagName> | 删除远程标签 |