天天看点

《Git操作全指南》来啦!内容总结:

《Git权威指南》书籍作者、阿里云云效资深技术专家 蒋鑫 在B站开课啦!

立即去B站围观:

https://www.bilibili.com/video/BV1Vq4y1S7zQ?spm_id_from=333.999.0.0
《Git操作全指南》来啦!内容总结:

内容总结:

Git十年十变化 #1

条件包含(IncludeIf)为不同目录下的仓库提供不同的默认设置
例如:不同目录下仓库提交使用不一样的邮箱配置(user.email)

git config --global includeIf.gitdir:~/work-alibaba/.path alibaba.inc

git config --global includeIf.gitdir:~/work-oss/.path oss.inc

Git十年十变化 #2

克隆操作对大仓库提供更好的支持

协议 2.0

git config protocol.version 2

稀疏检出

git clone --sparse …

git sparse-checkout init | add | reapply …

部分克隆

git clone --filter=blob:none …

Git十年十变化 #3

一个仓库可以拥有多个工作区(worktree),工作在一个仓库的不同分支上

创建新工作区

git worktree add -b topic-1 ../topic-1

如果切换至已检出到其他工作区的分支,报错

git switch topic-1

fatal: topic-1 is already checked out at ‘../topic-1’

清理工作区删除后,残存的Git管理文件

git worktree prune

Git十年十变化 #4

使用 core.fsmonitor 和 watchman 挂钩,为工作区提速

当仓库中包含非常多的文件时,git status 速度慢

安装 watchman,并为仓库做如下设置来提速:

git config core.fsmonitor .git/hooks/fsmonitor-watchman

mv .git/hooks/fsmonitor-watchman.sample .git/hooks/fsmonitor-watchman

Git十年十变化 #5

checkout 命令拆分为两条新命令:switch 和 restore,降低复杂的 checkout 命令的学习成本

创建并切换到新分支

git switch -c new-branch

使用暂存区版本覆盖工作区中指定文件

git restore -- file…

使用指定提交的版本覆盖工作区中指定文件

git restore -s v2.0.0 -- file…

Git十年十变化 #6

git-clean --interactive:采用交互式操作,清理本地未跟踪文件

开发此功能,源自一个网友问我如何找回 “git clean -f” 误删除的文件。

交互式清理本地未跟踪的文件和目录

git clean -i -d

交互式清理本地未跟踪的文件和目录,含忽略的文件

git clean -idx

关于交互式操作,查看帮助中 INTERACTIVE MODE 小节内容

git help clean

Git十年十变化 #7

git commit --fixup/--squash 以及 git rebase -i --autosquash 修改历史提交

修改历史提交通常使用 git rebase -i。参数 --autosquash 提供了自动化变基操作。

git commit --fixup=【amend:|reword:】 创建的新提交提供对指定提交的修正/修补/修改说明。

git commit --fixup # 新提交标题包含前缀 "fixup!:"

git commit --fixup=amend: # 新提交标题包含前缀 "amend!:"

git commit --fixup=reword: # 新提交标题包含前缀 "amend!:",无内容更改。

git commit --squash= 创建的新提交包含 "squash! " 前缀。

git rebase -i --autosquash 的交互式变基能够识别特殊的提交前缀,自动压合提交。可以使用配置 rebase.autosquash 设置--autosquash 为默认值。

Git十年十变化 #8

git range-diff 展示两个不同版本的多个提交之间的差异(包含提交说明的差异)

在 Git 项目的开源贡献中,经常使用此技术比较前后两个版本(reroll)之前的差异。

示例:

https://public-inbox.org/git/[email protected]/

Git十年十变化 #9

proc-receive 挂钩和 report-status-v2 带来服务端设计的创新

只读用户向仓库推送创建代码评审。(在

https://codeup.aliyun.com/

提供支持)

git push origin HEAD:refs/for/master/topic-name

客户端工具:支持 Gerrit 多仓库模式(比 git-submodule 更好的多仓模式)

git repo init -u manifest.git

客户端工具:单仓库快捷操作。参考:

https://git-repo.info/

git pr

git download ...

更多服务端创新已在路上...

Git十年十变化 #10

Git 中文本地化

2012年贡献了第一版本的中文本地化,并担任 Git 本地化国际协调者。

Git 本地化的 CI 工具:


https://github.com/git-l10n/git-po-helper

Git 本地化流水线:


https://lore.kernel.org/git/[email protected]/

中文本地化 Leader :周方易

参考 “po/README.md” 了解本地化流程,参与贡献。

后续 蒋鑫团队优秀的技术小哥哥们还有大波Git干货奉上,喜欢的朋友请持续关注阿里云官方B站账号,别忘了一键哦