[Git]使用git subtree與git submodule來拆解與管理專案

前言: 我想這樣的需求應該也不少,原本在專案的開發過程中,可能在一個respository會變得相當的大而且相當的肥.這時候可能要把一些專案拆解出去. 但是又希望有一個overview的專案在外面可以查看,研究了一下利用sourcetree想要達到這樣的方式,但是看起來還是得用git cli來使用. 範例: 以下的解釋都會透過這個範例,假設我們現在一有一個project_sample裡面有feature_a與feature_b.但是feature_a由於太受歡迎(真有這種feature???)所以很多產品都要使用,必須要獨立出來開發. 資料結構如下: project_sample feature_a feature_b 這時候,我們要把feature_a獨立出來成為另外一個repository並且希望開發project_sample的人可以一樣看得到feature_a. SourceTree沒有你想像的好用 Sourcetree是一套提供GUI的git tool,我個人不論是在Mac/Windows都有使用這套軟體.雖然bug不少,倒也算是涵蓋了我常用的幾個功能.不過要使用接下來的 git subtree split 就無法使用 sourcetree的UI,得用command line. 詳細步驟:切割repo 接下來的詳細步驟可以參考這個StackOverflow,以下以我提出的範例來做示範 : 在project_foo 下面,使用command line //這裏要注意的是: 如果是在Windows 路徑要使用 A/B/C 而不是 A\B\C git subtree split -P feature_a -b "branchA" 建立出新的branch之後,你會發現所有change list被切成兩個branch.一個是原本project_sample全部,另一個只有feature_a 接下來要把branchA submit到新的repository,建議路徑先不要在相同目錄下 mkdir <new-repo> cd <new-repo> git init git pull ../projhect_sample branchA git remote add origin <git@some-new-repro> git push origin -u master 如此一來會把剛剛另外一個branchA的所有內容submit到新的repo去.回來到就的repo,如果就的repo不需要留著原來的部分(我們接下來會用submodule import),就必須依照以下方式: // 如此會將所有與feature_a 目錄有關的檔案移除 git rm -rf feature_a 關於Subtree與Submodule取捨 如此一來,光是切割的部分已經算是完成了. 這個部分無法使用Sourcetree來完成. 接下來要把原來的Project_Sample來把feature_a作為一個submodule來輸入. 這裏我曾經有試過透過git subtree add的方式,把feature_a加回原來的project_sample.不過這樣sumit之後會把所有的code都submit而sub repo “feature_a”修改後無法正確的對應到 project_sample. (只有第一個人可以,其他clone下來的人會看成一個完整的repo 而喪失了subtree的link) 或許這個部分可能是操作上的錯誤. 持續研究中,我使用的是 submodule 來管理project_sample中的 feature_a. 詳細步驟:管理sub repo 接下來,可以使用Sourcetree來管理feature_a. [Repository]->[Add Submodule..] 選擇好你的feature_a,直接就可以Add Submodule進來. 由於是透過Sourcetree所以會直接clone下來並且在左邊會出現一個Submodules 更新Submodule: 接下來,如果你要更新Submodule裡面的程式碼,需要把滑鼠移到Submodules,並且選擇[Open Submodule] [Fetch] -> [Pull] //In Submodule 如此一來,你僅僅是你local把submodule的部份更新了.如果要所有的人都更新最新版本的submodule 還是需要submit submodule的tag. [Commit]->[Push] // submodule, in project_sample 修改Submodule: 如果要修改,一樣選擇[Open Submodule] [Commit]->[Push] //In Submodule 除了,local Push之外.你還需要sync submodule的tag. 回到原來的 project_sample commit “submodule”. [Commit]->[Push] // submodule, in project_sample ###參考文章: Stackoverflow: Detach subdirectory into separate Git repository GitSCM: 6.6 Git 工具 - 子模組 (Submodules) 第十三號艦隊: git subtree WMの物語:...
繼續閱讀

[MongoDB]More study about mongodb and mgo

Preface After some study about mongodb in some web server usage, I occur some question and need to resolve it. Here is three major questions I found here. Question 1: Auto increase number Question 2: Check field(column Auto increase number This question comes from the usage of MySQL auto increase sequence number. I am wondering if there is similiar mechanism in MongoDB. There is a official article about MongoDB implement auto-increasementing Sequence Field. The simple idea, is to add extra record in your database to storage this field. It might impact as follow: Your index might need to refere this field. Your query all need filter(ignore) the sequence record. (refer to “check field if exist”) For the FindAndModify mechanism in MongoDB, the mgo has similar implement about “Apply”. type DBSequence struct { ID string `json:"id"` // ID is a string ID, in this case I will use collection.Name as it...
繼續閱讀

[Golang][程式設計週記].. 2015第八週

##雜七雜八感言: 本週工作三天… 把一些春節沒看的文章看了一下.Golang 的新聞也似乎春節後開始變多….. BTW我也開始維護自己的一份pocket list,主要會放在這裡. ##筆記: Cutting-edge Web Technologies 網路課程 想要有系統的了解最新 Web Technologies 的人可以看看 Berkeley 開的 Cutting-edge Web Technologies 課程,slide 跟錄影都會放出來! [Golang] 關於Golang 有趣的網頁與小工具 [Golang] Operation Go 透過扮演兩個探員的故事,裡面穿插很多Go programing的測驗. [Golang] Go Language Patterns 關於design pattern 有關的資源 [Golang] Interactive X86 online compiler 可以看到cpu 跟原生assembly code的online compiler,其實LiteIde可以做到一樣的事情. Gohinetradio: Getting hinet online radio url & token and open without adobe flash. 用Go寫的讀取Hinet Radio 的小工具,寫的人是寫出python擷取台灣上市櫃股票grs的Toomore [Golang] Golang compiler full Go, no need C any more 雖然Compiler都用Go來寫,但是根據spec要編譯Go 1.5之後要使用Go 1.4的compiler有點繞口.不過好像其他語言也是這樣? [Golang] GoPanic Panic 是Go裡面一個發生錯誤會呼叫的函式,其實只是做memory dump而以.但是為了避免Panic 發生的時候,一些資料被竊取. Cold Boot Attack: 原本指的是加密的key寫在記憶體,卻被冷卻後移除電腦而直接讀取記憶體中的ram.也就是一種資料竊取的手法,而在網路裡面就是指發生panic的時候,卻從dump資料或是處理到一半的資料竊取到有加密的資料. 所以GoPanic 做的事情相當簡單: 建立一個UDP services 當系統呼叫propietary panic function (ex: do_panic() ),就會呼叫這個 UDP services 去做某些事情.(可能是關閉services或是清除暫存資料…等等) do_panic裡頭呼叫的處理部分需要自己處理. 這個部分可以參考 Python 的[panic_bcast](https://github.com/qnrq/panic_bcast
繼續閱讀

[Golang][程式設計週記].. 2015第六週

##雜七雜八感言: 最近工作都在弄Go的Server,應該之後會把心得整理一下. 發現用Go 來處理網路的相關封包,其實相當的方便又好用啊. ##筆記: ###[Golang] 一些有趣的package 跟 網站 pt: A path tracer written in Go. 一個用Goy做的光影追蹤程式,透過gopher 3D來繪圖. Dave Cheney: Visualising the Go garbage collector 一個工具可以使覺化Go GC的狀態圖.. Go Challenge: Learn Go by solving problems and getting feedback from Go experts! 怎麼快速學習程式語言?最好的方式就是拿它來解決問題,這邊每個月有一個問題提供出來~讓大家用Go來解決…. Fucking Go Date Format 列出一些讓人很困擾的Go Date format… Go concurrency is not parallelism: Real world lessons with Monte Carlo simulations 透過一些取樣方式來證明其實Goroutine並沒有那麼的並行…. JSON, interfaces, and go generate 關於Go裡面Json資料的處理方式….. Go: Socket-level Programming 教學文章… 用Go處理TCP或是UDP server/client其實相當簡單,可以處理的事情也幾乎都包好了.. 許多的細節.. 等我弄的差不多在整理文章….. Cockroachdb 大部份使用go完成的資料庫系統…. Githut: A SMALL PLACE TO DISCOVER LANGUAGES IN GITHUB 用圖形表示在Github觀察的現象,包含做多repostories 還有最多commit跟最多issue,也有最近最多人關注的部分…. A curated list of awesome Go frameworks, libraries and software http://awesome-go.com/ 有人記錄他覺得很棒的Go toolkit list根據他的分類.常常有忽然想到要什麼 toolkit 卻又想不到名字的窘境.. 看來maintain 自己一份toolkit list 也不錯…之前放 bookmark 後來放blog 還是一樣… 似乎有份list 比較重要.. 分門別類… tag Go-kit Peter 另外的list for morden enterprise. Go-kit.io 也是一份list gosms-Your own local SMS gateway Self host SMS system, sounds good, but I am using twilio for now. ###[Golang] 關於JSONRPC 心得筆記 利用JSONRPC package 可以很快速地建立一個JSON RPC Server/Client架構. 這裏有一個簡單的example可以參考,主要要注意的事情如下:...
繼續閱讀

[Golang]Study note about 'Taking Out The Trash talk'

What is this talk about Here is the talke Taking Out the Trash: Great talk about optimizing memory allocation. about Go memory optimize and GC. I have read it, and note my understanding as follow: ##Note: ###How does Go allocate / deallocate memory? Use stack for local variable and cleanup when return. Use heap when large local variale or compiler cannot approve are not referenced. It cleanup by GC. More detail in golangDoc- stack or heap Reserving Virtual Memmory Golang will reserve the virtual memory but not use it. If you want to know how much memory use by go need check “top” (check RES/RESIZE columns). (Refer to Dave Cheney:Visualising the Go garbage collector, you can see the system memory will not return by Go) When GC Run? Base on source code src/runtime/mgc0.c define the GOGC environment is 100. We could adjust it to change to GC period. The more...
繼續閱讀

[Golang]關於 Channels 的控制一些要注意的事項(一)

前言 學習Golang 讓人最興奮的大概就是它內建的 Concurrency 的支援,並且相當的容易使用. 但是最近在學習與使用的時候,發現發現 Goroutine 可以讓本來需要用到 40 秒的 Request 減少到1/3 左右的時間.進而可以進步到 5 秒左右.平常的應用上,幾乎已經離不開 Goroutine 與Channel。 但是最近遇到幾個例子,一開始覺得很不能理解,也不容易解決.也是讓我找了一些解決方式. 一般用法 Go Channel一般有兩種用法(當然有更多的使用方式可以用),一個是把channel當成資料來傳遞,另外的方式只是單純把channel當成是signal來等待或是啟動新的thread // 同時要處理多個可以同步運行的運算,利用channel來回傳結果 c := make(chan int) // Allocate a channel. go func() { result : = do_some_cal() c <- result }() c2 := make(chan int) // Allocate a channel. go func() { result : = do_some_cal2() c2 <- result }() totalResult := <-c2 + <-c fmt.Printf("result is %d"), totalResult) // 傳送訊號(signal)的方式 c := make(chan int) // Allocate a channel. go func() { list.Sort() c <- 1 // Send a signal; value does not matter. }() doSomethingForAWhile() <-c // Wait for sort to finish; discard sent value. 陷阱出現了 以上兩個方式相當的簡單,也相當直覺來使用.但是如果要跑goroutine的條件不是必要呢?也就是說不一定要透過go routine來同步執行很多的結果呢? c := make(chan int) //並不一定會進入go routine來計算,也就是說channel會是為空的. if needRoutine == true { go func() { result : = do_some_cal() c <- result }() } else { c <- 0 //note this kind will not work, because channels need input value in...
繼續閱讀