一, 查看:git
git status # 查看有变动的文件 git log # 显示当前分支的版本历史 git log --stat # 显示commit历史,以及每次commit发生变动的文件 git diff # 显示暂存区和工做区的代码差别 git blame [file] # 显示指定文件是什么人在什么时间修改过 git show [commit] # 显示某次提交的元数据和内容变化
git branch
# 列出全部本地分支
git branch -r
# 查看全部远程分支
git branch -a # 查看全部分支
二, 增长 建立分支 并提交到远程分支:bash
git branch -r # 查看全部远程分支 git branch -a # 查看全部分支 git checkout branch-name
# 新建一个分支可是依然停留在当前分支
git checkout -b branch-name
# 新建一个分支,而且切换到该分支
git branch --track[branch-name][remote-branch-name]
# 新建一个分支与指定的远程分支创建追踪关系
git branch --set-upstream [branch] [remote-branch]
# 创建追踪关系,在现有分支与指定的远程分支之间
git merge [branch]
# 合并指定分支到当前分支
三, 删除:spa
git branch -d [branch-name] # 删除分支 git push origin --delete [branch-name] git branch -dr [remote/branch] # 删除远程分支 1 git branch -r -d origin/branch-name git push origin :branch-name 删除远程分支 2
四, 代码回滚:指针
git checkout [file] # 恢复暂存区的指定文件到工做区 git checkout [commit] [file] # 恢复某个commit的指定文件到暂存区和工做区 git checkout . # 恢复暂存区的全部文件到工做区 git reset [file] # 重置暂存区的指定文件,与上一次commit保持一致,但工做区不变 git reset --hard # 重置暂存区与工做区,与上一次commit保持一致 git reset [commit] # 重置当前分支的指针为指定commit,同时重置暂存区,但工做区不变 git reset --hard [commit] # 重置当前分支的HEAD为指定commit,同时重置暂存区和工做区,与指定 commit一致 git reset --keep [commit] # 重置当前HEAD为指定commit,但保持暂存区和工做区不变 git revert [commit] # 新建一个commit,用来撤销指定commit # 后者的全部变化都将被前者抵消,而且应用到当前分支 git stash git stash pop # 暂时将未提交的变化移除,稍后再移入 git archive # 生成一个可供发布的压缩包 git reset --hard version-num # 回滚到指定版本 git revert HEAD 撤销前一次 commit git revert HEAD^ 撤销前前一次 commit git revert fa042ce57 撤销指定的版本,撤销也会做为一次提交进行保存。