2016/10/11

Just a Note:Use GIT as SVN Client

2016.10.03 補充:
略過不要 fetch 的目錄。

當團隊中有人使用非 Windows 系統時,可能會發生 svn 中出現 Windows 無法接受的字元的目錄,
即使事後刪除了,但這樣的資訊仍會存在 history 中。

若此時使用 git svn 進行 fetch,便會發生無法建立目錄的錯誤。
此時可以透過 sparse checkout 避開這樣的目錄,具體步驟如下:

1. git config core.sparseCheckout true
2. 查看 .git/info 目錄下是否有 sparse-checkout 檔案,若無,新增一個。
3. 在檔案中加入
/*
!不要的目錄路徑

4. 重新執行 git svn rebase 或 git svn fetch

5. 即使加了上述的設定,在 git svn rebase 時,還是會有問題,此時就必須額外加上 --ignore-paths 忽略有問題的路徑:
git svn clone some_svn_url . -s --prefix=svn/ --ignore-paths="^(?:trunk|branches|tags)/不要的路徑"
git svn rebase --ignore-paths="^(?:trunk|branches|tags)/不要的路徑"


沒想到已經三年沒寫筆記了......

2016/04/07

Just a Note:Git Submodule

紀錄 git submodule 多人共用的情境與步驟。

1. 第一個新增 submodule 的人
git submodule add -b [submodule_branch] [submodule_url] [submodule_folder] (submodule_folder 需不存在,會產生或更新 .gitmodules)
git submodule init (register submodule in git)
git submodule update (把 submodule 的檔案更新回來)
git add .
git commit -m "add submodule"
git push

2. 其他人
git pull (submodule 目錄會是空的)
git submodule init (register submodule in git)
git submodule update (把 submodule 的檔案更新回來)

3. 更新 submodule:
(1) 在 submodule 原始的 repository (不是在此系統的 repo 下)修改,按照標準 git 程序進行更新。
(2) 直接在此系統的 submodule 目錄下進行修改:
cd [submodule_folder]
git add [stuff]
git commit -m "[comment]"
git push origin HEAD:[submodule_branch]

4. submodule 有更新,第一個處理 submodule 更新的人
git submodule update --remote (更新 submodule 檔案及 local git 紀錄的 submodule hash)
git add .
git commit -m "submodule update"
git push (如此 remote server 的 submodule reference 才會更新,否則其他人都還是會用到舊版的 submodule)

5. 其他人
git pull
git submodule update


參考:
Git submodules: Specify a branch/tag
http://stackoverflow.com/questions/1777854/git-submodules-specify-a-branch-tag
Git Submodule 的認識與正確使用!
http://josephjiang.com/entry.php?id=342
Issue with adding common code as git submodule: “already exists in the index”
http://stackoverflow.com/questions/12898278/issue-with-adding-common-code-as-git-submodule-already-exists-in-the-index
How do I remove a Git submodule?
http://stackoverflow.com/questions/1260748/how-do-i-remove-a-git-submodule
git submodule update --remote vs git pull
http://stackoverflow.com/questions/19619747/git-submodule-update-remote-vs-git-pull
git-submodule(1) Manual Page
http://git-scm.com/docs/git-submodule