自用Git指令
常规操作
查看修改
git diff a.txt
提交日志
git log
添加所有变化的文件
git add .
添加名称指定文件
git add text.txt
提交暂存区到仓库区
git add .
git commit -m "msg"
git commit -am 'msg'
提交时显示所有diff信息
git commit -v
显示所有远程仓库
git remote -v
显示某个远程仓库的信息
git remote show [remote]
下载远程仓库的所有变动
git fetch [remote]
增加一个新的远程仓库,并命名
git remote add [shortname] [url]
取回远程仓库的变化,并与本地分支合并
git pull [remote] [branch]
上传本地指定分支到远程仓库
git push [remote] [branch]
强行推送当前分支到远程仓库,即使有冲突
git push [remote] --force
推送所有分支到远程仓库
git push [remote] --all
列出所有本地分支和远程分支
git branch -a
新建一个分支,但依然停留在当前分支
git branch [branch-name]
新建一个分支,并切换到该分支
git checkout -b [branch]
新建一个分支,指向指定commit
git branch [branch] [commit]
新建一个分支,与指定的远程分支建立追踪关系
git branch --track [branch] [remote-branch]
切换到指定分支,并更新工作区
git checkout [branch-name]
切换到上一个分支
git checkout -
合并指定分支到当前分支
git merge [branch]
删除分支
git branch -d [branch-name]
删除远程分支
git branch -dr [remote/branch]
显示有变更的文件
git status
显示当前分支的版本历史
git log
# 显示commit历史,以及每次commit发生变更的文件
$ git log --stat
根据关键词搜索提交历史
git log -S [keyword]
显示某个文件的版本历史,包括文件改名
git log --follow [file]
显示指定文件相关的每一次diff
git log -p [file]
显示过去5次提交
git log -5 --pretty --oneline
显示指定文件是什么人在什么时间修改过
git blame [file]
显示暂存区和工作区的差异
git diff
显示当前分支的最近几次提交
git reflog
恢复暂存区的指定文件到工作区
git checkout [file]
重置暂存区的指定文件,与上一次commit保持一致,但工作区不变
git reset [file]
重置暂存区与工作区,与上一次commit保持一致
git reset --hard
暂时将未提交的变化移除,稍后再移入
git stash
git stash pop
恢复暂存区的所有文件到工作区
git checkout .