Git 常用指令笔记

190 阅读2分钟

在实际使用 Git 进行开发的过程中,比较常用的一些指令笔记

基本概念

英文中文
working tree工作区
stage/index暂存区
origin远程、源
tag标签
mainline主线

git-commit

Record changes to the repository

向仓库提交改动

命令描述
-n, --no-verify该选项可以避免执行 pre-commitcommit-msg 钩子

git-tag

Create, list, delete or verify a tag object signed with GPG

创建,列举或者删除标签

命令描述
git tag -a [tagname] -m [msg]创建标签并添加信息
git tag -l列表本地标签
git tag -d [tagname]删除本地标签
git push --tags向远程推送所有本地标签
git push origin :refs/tags/[tagname]删除远程标签

git-stash

Stash the changes in a dirty working directory away

把工作空间中所有暂存和非暂存的改动隐藏起来

命令描述
git stash快速隐藏
git stash push [-m <message>] [--] [<pathspec>…​]添加备注并指定路径
git stash list以列表的形式展示
git stash pop [<stash>]把栈顶的改动应用到本地,并删除栈顶
git stash apply [<stash>]把栈顶的改动应用到本地
git stash clear删除远程标签

git-clean

Remove untracked files from the working tree

从工作区中删除未跟踪的文件

命令描述
git clean [-d] [-f]删除指令
-d递归地删除目录和目录下包含的所有目录和文件
-f, --force如果不添加该选项,git clean会没有删除文件和目录的权限

git-revert

Revert some existing commits

撤销已经存在的提交

通过创建新的提交,去撤销已经存在的提交

命令描述
git revert [commit]撤销一个已经存在的提交
-n, --no-commit不创建新的提交,直接把撤销后的代码添加到工作区和暂存区

git revert [start-commit]..[end-commit]

撤销指定区间的提交,前开后闭,不包括[start-commit],包括[end-commit]

git revert -m 1 [merge-commit]

--mainline parent-number

通过指定主线撤销合并,parent-number1 开始,通过git show [merge-commit]查看

参考文档

offiaccount