每天和 git 打交到的时间算是前几位了,总结一些问题,不断更新。。。
- 技术层面 git help XXX 能解决几乎所有疑惑,经验方面,遇到和解决的问题越多,思考也就越多;团队管理和规范推行方面,充分尊重工程师的感受,考虑团队的情况
看过很多项目,或者解决定位线上问题 —— 快速清理无用的调试工作区
1 | git clean |
gitlab 项目管理
分支保护(代码提交合并权限问题)
settings => repositoryprotected branches => expand
https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git.html
gitlab continuous integration
/settings/integrations
分支名称自动补全
指路:https://ohmyz.sh/(oh my zsh)
git 清除本地无远端的分支(清除本地所有分支)
强制删除所有分支
git branch |xargs git branch -D
本地修改过未提交的不会删除
git branch |xargs git branch -d
迁了一次仓库,团队人员变迁,所以目前一些项目的文档和说明及 package.json 不是很准确
git remote show origin
rebase/merge
推 rebase 的经验,可以写一篇小论文了。。。
rebase 伴侣 => –force-with-lease
文档指南:
重写历史的时候可以使用的命令及需要注意什么
https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History
git 报错分析
1 | error: src refspec master does not match any. |
没有提交内容,要 add 和 commit (引起该错误的原因是,目录中没有文件,空目录是不能提交上去的)
重写历史需注意
https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E5%86%99%E5%8E%86%E5%8F%B2
github/gitlab
1 | curl -s <github_url> | vim - |
通过管道把 curl 命令的输出传给 VIM,以方便在 VIM 中查看较长的输出。
好用的命令行工具
tig(https://jonas.github.io/tig/)
1 | brew install tig |
查看 working tree 的状态
git-status - Show the working tree status
切换分支的时候,注意查看
gitk(the git repository browser)
https://git-scm.com/docs/gitk/
.gitignore 规则生效
如果一旦纳入版本管理,可以先删除本地缓存,然后提交
1 | git rm -r --cached . |
.gitignore 参考
https://docs.github.com/en/github/getting-started-with-github/getting-started-with-git/ignoring-files
导出某个项目的作者
1 | "authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS" |
git shortlog -s -n
新建项目
rm -rf .git
项目过大问题,或者误提交大文件
1 | # 找出大文件 |
跨项目关联推送分支
A 是模版项目
B 是用了模版项目的业务项目
- 模版项目 A 更新了基础配置,可以切一个分支,feature/update-basic
- 在 B 中也新建一个分支 feature/update-basic
- 将 A 的远端源切换成 B
- 推送本地 feature/update-basic 分支到远端即可
修改提交 message
切记,如果推送到了远端,保证一定不是协作分支,不然最好确保都是本地操作
1 | # 显示倒数n次的commit msg |
commit message
1 | https://www.npmjs.com/package/@commitlint/config-conventional#type-enum |
关联远端仓库
1 | # 先查看下 |
注意区分上面的概念
1 | 用git remote add <name> <url>添加一个远程仓库,其中name可以任意指定(对应上面的origin部分) |
上面两个操作,对应pull,push的时候,操作不一样,因为pull,push的时候需要指定repo
tag
文档指路:https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE、
1 | # 引自文档 |
1 | # annotated |
husky
1 | "lint-staged": { |
yorkie
- “githooks management forked from husky”
- “authors”: [
“Typicode typicode@gmail.com“,
“Evan You”
],
.git
1 | # v8 - README.md |
git branch
- https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF
- git branch -vv
Divergent history
git log –oneline –decorate –graph –all
工具
sourcetree
搜索某个人提交
View - Search View - User
git log –author==”xxxx”
github
快捷键: t , w 快速进入搜索
resolving Deltas
- https://stackoverflow.com/questions/4689844/what-is-git-actually-doing-when-it-says-it-is-resolving-deltas
- 解压和校验整个 repo 数据库
tfs
- tfs 删除仓库,版本控制,先把自己添加到用户里面,再给自己加上删除的权限,就可以删除了
不想cd到具体目录,但是想查信息
git -C "/Users/xxxx/Development/Projects/xxx/xxxx" status === git --work-dir="/Users/xxxx/Development/Projects/xxx/xxxx" --git-dir="/Users/xxxxx
git prune
error: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log.
git prune && git gc # Remove loose objects
git fsck –lost-found
sourcetree 里面我这边自动开了推送所有的tags
1 | --tags |
git push --tags
推送所有tags
git help tag
git help push
npm list -g –depth 0
GitStats - git history statistics generator
https://gitstats.sourceforge.net/
git fetch -p
- 清除已删除的远程分支