我的另一篇关于 Git 的文章:https://crayonuno.github.io/posts/tech/git/。
总结了平时常用的 Git 命令,和丰富的推荐学习资料。
有两种方式设置 Git 命令别名。
第一种找到用户主目录下的 .gitconfig 文件,将下面的内容自己复制到文件中即可。
第二种直接通过命令行进行设置。ex: git config --global alias.co checkout(最后也是体现在 .gitconfig 文件中)。
[alias]
co = checkout
cob = checkout -b
br = branch
brs = branch --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative)) [%(authorname)]' --sort=-committerdate
ci = commit
cm = commit -m
save = !git add -A && git commit -m 'chore: commit save point'
undo = reset HEAD~1 --mixed
unstage = reset HEAD --
st = status
du = diff @{upstream}
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
history = log --oneline --graph
last = log -3
-
brs:用较好的可读性,列出所有分支的相关信息
-
git cm "在这里直接添加你想要的提交信息" -
save:用定义好的提交信息,先提交工作区,再提交暂存区的所有内容,生成一次 commit。
-
undo: reset 上一次提交的内容
-
unstage: 暂存区回到工作区,类似撤销执行 git add .
-
du: 比较和远程分支的内容差别。一般要先 git fetch 一下
-
lg:用较好的可读性,列出当前分支下的提交信息
-
history:和 lg 差不多,列出了远程分支的 head 指向
-
last:列出最近三次提交
参考链接: