git <command> --help |
查看帮助,命令选项可省略; |
git init |
初始化 repo,生成 ./.git/ 相关配置; |
git add <file> |
添加指定文件进入暂存区; |
git commit -m '<commit msg>' |
将暂存区中的改动连同说明添加进入版本控制; |
git status |
查看本地 repo 的改动状态; |
git diff <file> |
查看指定文件与 repo 的差别;git diff HEAD -- <file> |
git reset --hard HEAD^ |
回退到上一个版本;HEAD 表当前版本,HEAD^ 表上一个版本,一次类推;HEAD 指向当前分支,亦可替换为指定 commit ID |
git log |
查看提交日志; |
git log --pretty=oneline |
以简单模式查看提交日志; |
git log --graph |
以图表模式查看提交日志; |
git log --abbrev-commit |
以省略 commit ID 模式查看提交日志; |
git reflog |
查看命令历史; |
git checkout -- <file> |
清空工作区指定文件的改动; |
git reset HEAD <file> |
将已提交到暂存区的改动撤销回工作区; |
git rm <file> |
删除指定文件; |
git branch <branch> |
创建新分支; |
git checkout <branch> |
切换到指定分支; |
git checkout -b <branch> |
创建并切换到新分支; |
git merge <branch> |
将当前分支合并到指定分支;默认 Fast forward 模式; |
git branch -d <branch> |
删除指定分支; |
git branch -D <branch> |
强行删除指定的没有被合并过的分支; |
git merge --no-ff -m '<commit msg>' <branch> |
将当前分支合并到指定分支;不使用 Fast forward 模式,将增加一个新的 commit 以示合并; |
git stash |
存储当前分支的改动,以便切换到其它分支上工作;执行后将清空工作区; |
git stash list |
列出所有存储; |
git stash pop |
恢复并删除存储; |
git stash apply stash@{<index>} |
恢复指定存储; |
git stash drop |
删除存储; |
git remote -v |
查看详细的远程 repo (默认名为 origin) 信息; |
git push orgin <branch> |
将本地分支推送到指定的远程分支上; |
git clone <link> |
克隆远程 repo; |
git checkout -b <branch> origin/<branch> |
创建远程 origin 分支到本地; |
git tag |
查看所有标签,按字母顺序列出; |
git tag <tagname> <commit ID> |
对指定 ID 的 commit 创建自定义标签; |
git show <tagname> |
查看指定标签信息; |
git tag -a <tagname> -m '<commit msg>' <commit ID> |
创建带有说明信息的标签; |
git tag -d <tagname> |
删除指定标签; |
git push origin <tagname> |
推送指定标签到远程 repo; |
git push origin --tags |
一次性推送全部尚未推送到远程 repo 的本地标签; |
git push origin :refs/tags/<tagname> |
从远程 repo 删除标签,需先本地删除后在执行; |
git check-ignore -v <file> |
查看指定文件是否在 .gitignore 忽略规则中; |
git config --global alias.<command-alias> <command> |
配置命令别名,配置表存储在 .git/config 中; |