git tag 常用笔记
查看 tag
-
列出现有 tag
git tag
-
列出 v1.4.2 相关的 tag (
*
是通配符)git tag -l "v1.4.2*"
-
查看指定 tag 的信息
git show v1.2.3
-
查看包含指定提交的 tag
git tag --contains <commit>
新建 tag
-
简单新建
git tag v1.2.3
-
带备注的新建
git tag -a v1.2.3 -m "your message"
-
给指定 commit 添加 tag
git tag -a v1.2.3 -m "your message" 9fceb02
推送 tag
-
推送指定 tag
git push origin v1.2.3
-
推送所有 tag
git push origin --tags
删除 tag
-
删除本地 tag
git tag --delete v1.2.3
-
删除远端 tag
git push origin --delete tag <tagname>
参考链接
alias
git config --global alias.lg "log --graph --pretty=tformat:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --decorate=full"
gitignore
以下回答来自 GPT4
在 Git 中使用 .gitignore
文件排除特定文件或文件夹后,如果需要重新包含某些被排除的内容,可以通过以下步骤实现,以特定路径的 x64 文件夹为例
1 编辑 .gitignore 文件: 如果你只想排除大部分 x64 文件夹,但保留特定的 x64 文件夹,可以在 .gitignore 文件中进行更精细的配置。例如,假设你有一个 x64 文件夹在 path/to/ 目录下,你可以这样修改 .gitignore 文件:
# 排除所有 x64 文件夹**/x64/
# 但排除特定 x64 文件夹!path/to/x64/
2 使用 git add -f 命令:
如果你已经提交了 .gitignore 文件,并且想要强制添加被忽略的文件或文件夹,可以使用 git add -f 命令。例如:
git add -f path/to/x64
3 使用 git check-ignore 命令: 如果你不确定某个文件或文件夹是否被忽略,可以使用 git check-ignore 命令进行检查:
git check-ignore -v path/to/x64
其他命令
使用解决冲突的方式合并,将避免简单的自动合并
git merge origin/dev --strategy=resolve
清理本地已经合并到 dev 的分支
git branch --merged | grep -v 'dev' | xargs -n 1 git branch -d
分支清理
Git 之删除本地无用分支_dearfulan 的博客 - CSDN 博客_git 删除本地无效分支
git fetch -pgit remote prune origin
查看两个分支的最近共同祖先
git merge-base [-a|--all] <commit> <commit>…
包含某个提交的分支或TAG
git branch --contains <commit>git branch -r --contains <commit>git tag --contains <commit>
统计 git 提交数
git rev-list --count HEAD
git 列出 HEAD 的 提交号
git rev-parse HEAD
# 如果只是查看,则直接使用 show 命令就可以git show HEAD
git 别名
git config --global alias.co checkoutgit config --global alias.lg log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
换行符问题
提交检出均不转换
git config --global core.autocrlf false
允许提交包含混合换行符的文件
git config --global core.safecrlf false
查看提交日志
git reflog show --color --abbrev-commit --all --pretty=oneline --date=short --after="2020-05-22" | grep 'commit' | grep -v 'refs'
空提交
git commit -m "version + 2" --allow-empty
其他
原文链接: https://blog.jgrass.cc/posts/git-command-note/
本作品采用 「署名 4.0 国际」 许可协议进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。