Git bundle 離線同步的技巧

Dian
Jun 10, 2022

--

git 的方便是分散式的程式碼版本控制器,就算是同一個目錄下,也是可以同時切出不同的 branch 對應到不同的遠端 server 可以說是十分的靈活。

通常在開發時,都會在 server 開一個新的 branch 對應一個新的功能,讓團隊保持又分工又合作的情況。

不過如果遇到了 server 無法隨便開 branch 的情況,通常就只是在開一個只存在 local 端的 branch ,這樣有一個壞處就是你開發到一半的版本無法與其他人合作開發或是自己想要換一台電腦開發,就只能直接用複制的方式將修改過的檔案移到另一台電腦上,如果只有修改一兩個檔案可能還好,如果是五個十個二十個檔案,就有可能不小心漏了幾個檔案,一次兩次就受不了。

還好 git 本身就提供了離線同步的方式 git bundle 🎉🎉🎉
只要兩台電腦有相同的 branch 就可以使用 git bundle 簡單的同步 commit 內容,除了可以保留完整的 commit log, git bundle 產出的檔案也是小小的只記錄修改的部分。而且也有 verify 機制在兩邊的 commit log 是對不上的情況,也無法直接匯入。

總結一下,透過 git bundle 就可以用離線的方式同步兩台電腦的 commit 記錄,要注意的是打包 commit 的位置要正確,就只差一個 commit git 也是會把被擋下來的。

參考資料:
https://git-scm.com/docs/git-bundle

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Dian
Dian

Written by Dian

學習>吸收>實作>再學習

No responses yet

Write a response