Created
July 1, 2016 09:13
-
-
Save thebrecht/ab680a1731bc0cca5623b4a78d1224f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
不知道 Drupal/wordpress 這類專案的開發者,在使用git作版本控管時,會管理哪些範圍? | |
會有這個疑問,就以 Drupal而言,不管是核心程式,或是掛進來的第三方 module,這些基本上都不需要做程式碼的控管,因為不是自己開發的,正常的情況下也不會去動到這些東西,就我來說,也就不需要去管理這些程式碼。 | |
在這樣的思路下,公司的一個專案因為只有客製 theme ,所以我只用 git 這個目錄。然後在 deploy的過程跟 bitbucket 綁在一起,一旦 theme 有更新,推到 production branch時,也會同步更新 production的 code。 | |
隨著使用時間日久,有了需要開發自己 module 的需要,因此就有需要新追蹤的範圍。原本有想過不然就開另一個 git repo來作版本控管,但是這樣增加管理上的麻煩,以及如果有同時更新 module和 theme的時候,同步就要推兩次,這樣子實在不科學啊。 | |
想了想,決定把記錄版本資訊的 .git 目錄移動,達到我想要的目的。 | |
.git 目錄換位置 | |
sites/ | |
all/ | |
modules/ | |
third-party-module-a | |
third-party-module-b | |
custom-module | |
themes/ | |
theme-a | |
thema-b | |
custom-theme/.git | |
上面是過去的目錄結構,.git放置在 theme的custom-theme下面,為了連module都可以管理,應該要上移到 all 這一層目錄中,也就是變成這樣: | |
sites/ | |
all/ | |
.git | |
modules/ | |
third-party-module-a | |
third-party-module-b | |
custom-module | |
themes/ | |
theme-a | |
thema-b | |
custom-theme | |
雖然知道 git 檔案控管資訊通通存在 .git 目錄中,理論上移動位置就可以了。不過為了保險起見,還是開了一個類似結構的目錄來測試一下,當 .git 目錄往上搬移到 all 之後,相當於你自己手動往下搬移了theme、module那些檔案(就好像坐火車時,感覺是窗外的景色在跑,而不是車子在動),所以 .git 會做的事是重新建立目錄結構和檔案,只要下一次: | |
git add --all | |
原本沒有被納入管理的檔案,以及搬移過程的異動資訊,就全部加進來了,之後就commit收工了。 | |
那些不想收進來的檔案 | |
上面講的是理論,但事實上還有一個問題,就是有些目錄我不想納入。在modules底下,我只想要 custom-moudle被 git 追蹤管理,在 themes 底下,我也只想 custom-theme這個目錄被管理,其他的都是第三方的東西,沒有必要加進來。 | |
這個說起來也不難,就是用 .gitignore來處理就可以了。 | |
我大約記得,要下例外的作法,就是前面加驚歎號即可。以我的目錄來說,我想成這樣 | |
# 錯誤的例子,大家不要學 | |
/modules | |
/themes | |
!modules/custom-module | |
!themes/custom-theme | |
上面的想法大致就是 modules 和 themes 底下的目錄我都不追蹤中,但各目錄中的 custom 目錄是例外,這個要做版本控制。 | |
但這個設完之外,例外規則感覺沒有發生作用,custom 目錄底下有異動時,打 git status 查看,還是靜悄悄的。 | |
亂試半天之後放棄,到 https://git-scm.com/docs/gitignore 查看語法,才知道原來我想要的做法,必須用下面的方式來指定。上面的做法其實從目錄層就已經封殺了,沒辦法降下來例外,而下面的設法才是直接在談論 modules 或 themes 底下的目錄該如何排除及例外處理。 | |
# 這才是正確的設法 | |
/modules/* | |
/themes/* | |
!modules/custom-module | |
!themes/custom-theme | |
其實上面都是些簡單的觀念,只是沒遇到時就不會真正理解或處理啊。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment