天天看點

《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站賬号,别忘了一鍵哦