Bitbucket 寄來一封會員信,標題非常吸引大家的注意,那就是 Bitbucket now rocks Git.,是的,你沒看錯,Bitbucket 現在開始支援 Git repository,不再只有 Mercurial 可以使用,這還不算什麼,Bitbucket 更是推出**無限制免費 private repos for free **,這樣的推出,不知道會有多少 Github 用戶轉移到 Bitbucket 上面,還有另一項主因就是 Unlimited disk space 無限制硬碟容量,不過也許不用高興的太早,Bitbucket 在使用者人數上面有些限制,可以參考 Plans & Pricing,免費方案每個 Repository 只能有5個 User,反觀 Github 並沒有這限制,不過我想這也不是問題,大家可以 Fork 到自己的專案,在 Pull Request 即可。 補充官方網站提供了轉換各大 Source Hosting 工具,目前支援 Github、SourceForge、Google Code、Subversion、Mercurial…等。
版本控制 svn move 移動或更名
公司採用 svn 當作版本控制,而我最近在整理 svn 上面全部的 source code。基本上我都會將 git 跟 svn 也一起搭配著用,因為個人比較熟悉 git 的操作方式,然而跟同事討論了專案目錄的架構,進而要把一些目錄轉換大小寫,本來的 App 就改成 app,這個在 git 底下(OS: Linux)操作非常容易,直接 git mv App app,之後看 git status 可以發現底下輸出:
# On branch develop # Changes to be committed: # (use "git reset HEAD可是在 svn 的流程不是這樣喔,首先 svn 會將原本的目錄先刪除,再來新增一個新目錄。這樣就算了,在 Windows 底下還不讓你這樣操作,請先裝..." to unstage) # # renamed: nav/hacks.txt -> Nav/hacks.txt # renamed: nav/moo.fx.js -> Nav/moo.fx.js # renamed: nav/moo.fx.pack.js -> Nav/moo.fx.pack.js # renamed: nav/nav.js -> Nav/nav.js # renamed: nav/prototype.lite.js -> Nav/prototype.lite.js # renamed: nav/user_guide_menu.js -> Nav/user_guide_menu.js #
Subversion Client,然後請在"開始"->“執行” 打入 cmd,可以透過 svn mv 方式來操作
[Read More]Git Submodule 介紹與使用
自己用 Git 已經很長一段時間了,沒用過 git submodule 的話真的是對不起自己,今天來筆記 Git Submodule 一些操作步驟及說明。
git Submodule 使用時機
大家在開發新專案的時候,不知道有沒有用到其他專案的程式碼,像是 Web 專案,也許會用到 Blueprintcss CSS Framwork 或者是 Sass,這些專案目前都放在 Github 上面進行維護,以前的作法就是先 git clone 下來,把要的檔案分別複製到自己專案,可是問題來了,如果官方更新了程式碼,那自己的專案如何更新呢?難道是重複步驟把檔案複製到原來地方嗎?這樣會不會太麻煩,這時候就是需要 git submodule 來幫助大家進行程式碼的更新,這樣隨時隨地都可以取得最新的程式碼。補充說明一點,git 目前無法針對單一專案底下的單一檔案或目錄進行 clone,而必須 clone 整個目錄,這點跟 svn 有很大的不同,所以 git 可以建立各個不同的 submodule 來整合成一個大型 Project。換句話說就是: 在您的專案底下,你可以任意將其他人的專案掛載在自己任何目錄底下。
[Read More]用 git 指令產生 Change log 格式
Git 真的是一套非常好用的版本控制工具,在網路上看到一篇 Making a Changelog from Git commit messages 裡面提到一篇新手必看的 git branch model,剛好這篇我也寫了中文解說的部份『Git 版本控制 branch model 分支模組基本介紹』,回歸正題,此篇是介紹如何用 git 指令產生 Change log 檔案,平常 Change log 都會寫成類似底下的 format:
- Add Chinese Traditional language file - Changed to use count_all_results. - Added permissions checking to activation in example controller. - Fixed an example in the userguide - changed phrases to more typical ones在 git log 裡面寫了很多 commit message 該如何 format 成上面的格式呢,其實很簡單,只要打入下面指令
# #--no-merges: 不要秀出 merge message #--pretty=format:' - %s' : 關鍵 format git log --no-merges --pretty=format:' - %s'另外我們還可以透過 --graph 顯示圖形式的 log 顯示,指令如下:
git log --graph --pretty=format:'%s - %Cred%h%Creset %Cgreen(%cr)%Creset %an' --abbrev-commit --date=relative顯示結果如下
* Add Chinese Traditional language file - 1767c60 (4 months ago) Bo-Yi Wu * Changed to use count_all_results. - 906d101 (4 months ago) Ben Edmunds * Merge branch 'master' of https://github.com/Kohtason/CodeIgniter-Ion-Auth into Kohtason-master - 599188d (4 months ago) B en Edmunds |\ | * Fixed an example in the userguide - 65b0e05 (4 months ago) Sven Lueckenbach | * changed phrases to more typical ones - 1941831 (4 months ago) Sven Lueckenbach | * added ability to get usercount - b404fc3 (4 months ago) Kohtason | * added ability to get usercount - b51e801 (4 months ago) Kohtason | * added ability to get user-count - 11a85da (4 months ago) Kohtason * | Added permissions checking to activation in example controller. Fixed bug in activation method in model. (via Phil Gyford) - c9ff 467 (4 months ago) Ben Edmunds不多說,補一張圖,讓大家看看
svn 恢復略過衝突檔案 (conflict file)
當我們利用 svn up 更新程式碼,如果遇到修改相同檔案的相同地方,就會發生衝突 (conflict) 此時就必須修改或者是略過,當選擇略過此檔案就會出現底下訊息
Skipped ’lib/logs/logDB.txt’ Skipped ’lib/confs/Conf.php’ At revision 912. Summary of conflicts: Skipped paths: 2 之後怎麼用 svn up 更新檔案,都會因此被略過,那該怎麼恢復被略過檔案的狀態,讓它們可以繼續被更新呢?網路上找到一篇 svn local obstruction, incoming add upon merge 解法,用 svn resolve 來解決問題,只要針對該檔案打入底下指令即可
svn resolve --accept working lib/confs/Conf.php svn resolve --accept working lib/logs/logDB.txt
Git 版本控制:利用 git reset 恢復檔案、暫存狀態、commit 訊息
這次來介紹一下 git reset 的用法,為什麼會介紹這指令呢?因為今天想要看專案狀態,用 git status 觀看,發現被我玩爛了,所以出現了底下錯誤訊息:
$ git status error: bad index file sha1 signature fatal: index file corrupt解決此問題非常簡單,要先刪除 index 檔案,請先砍掉
.git/index,恢復此 index 請用
git reset這行指令相當於
git reset –mixed HEAD,或者是可以用 git read-tree 來取代 git reset,當然 git reset 不只是有這功能而已,假如您已經建立了 commit 訊息,也可以將此訊息拿掉,重新在 commit,或者是您修改過的檔案在暫存區,git 也可以幫您恢復到未暫存,或者是不想要這次的修改,也可以恢復到未修改的檔案喔。
取消已經暫存的檔案 假如我們有兩個檔案需要 commit,但是不小心按到 git add * 全部加入到暫存區,那該怎麼恢復呢?
# On branch master # Changes to be committed: # (use "git reset HEAD上面是以經在暫存區裡面等待被 commit 檔案(..." to unstage) # # modified: Makefile # modified: user/easy_setup/easysetup.h #
Changes to be committed),大家可以看到括號裡面有提示如何拿掉 (use “git reset HEAD
git reset HEAD user/easy_setup/easysetup.h之後會看到 『
user/easy_setup/easysetup.h: locally modified』此訊息,這時候在用 git status 看狀態
# On branch master # Changes to be committed: # (use "git reset HEAD[Read More]..." to unstage) # # modified: Makefile # # Changed but not updated: # (use "git add ..." to update what will be committed) # # modified: user/easy_setup/easysetup.h #
Git 版本控制: 「You have some suspicious patch lines」
相信大家對 Git 並不陌生,這次在升級 Moztw 的討論區,從 3.0.5 升級到 3.0.7 p1,過程由其他 Moztw 成員升級,我在將最後程式 commit 到 github,因為兩個版本差異性很大,所以有新增多個檔案,commit 過程出現了錯誤訊息:「You have some suspicious patch lines」,這是因為 git 會檢查每行程式碼最後是否有多餘空白或者是 Tab 按鍵,為瞭解決此問題,可以去修改 .git/hooks/pre-commit,將底下程式碼:
if (s/^\+//) {
$lineno++;
chomp;
if (/\s$/) {
bad_line("trailing whitespace", $_);
}
if (/^\s* \t/) {
bad_line("indent SP followed by a TAB", $_);
}
if (/^([<>])\1{6} |^={7}$/) {
bad_line("unresolved merge conflict", $_);
}
}改成:if (s/^\+//) {
$lineno++;
chomp;
# if (/\s$/) {
# bad_line("trailing whitespace", $_);
# }
# if (/^\s* \t/) {
# bad_line("indent SP followed by a TAB", $_);
# }
if (/^([<>])\1{6} |^={7}$/) {
bad_line("unresolved merge conflict", $_);
}
}暫時停止 git 過濾字串,等 commit 完成之後,在將其 unmask 掉。 參考網站:[Git] how to remove file and commit from history(如何移除 commit 歷史紀錄)
今天在 commit 程式碼到 github 網站,不小心把 Plurk 帳號密碼給 commit 上去,發生這種事情,所以趕快上網查了一下如何移除 commit 歷史紀錄: 假設我們的 commit tree 如下:
R–A–B–C–D–E–HEAD 接下來要移除 B 跟 C 的 commit tree,變成
R–A–D’–E–HEAD 有兩種方式可以移除 B & C
# detach head and move to D commit git checkout另一種方法是利用 cherry-pick 方式# move HEAD to A, but leave the index and working tree as for D git reset --soft # Redo the D commit re-using the commit message, but now on top of A git commit -C # Re-apply everything from the old D onwards onto this new place git rebase --onto HEAD master # push it git push --force
git rebase --hard這會直接忽略 B 跟 C 的 history,詳細資料可以查詢 git help cherry-pick 或者是 git help rebase 參考:git cherry-pick git cherry-pick
Git: removing selected commits from repository Git: how to remove file and commit from history Re: ! [rejected] master -> master (non-fast forward)
[FreeBSD] 簡易架設 git Server,git 使用教學
Git 是一套免費 open source 的版本控制軟體,另外還有很多套版本控制軟體,如:Mercurial, Bazaar, Subversion, CVS, Perforce, and Visual SourceSafe,其中 Mercurial 又是 Google Code Project Hosting 採用的版本控制系統,當然 google 也支援原本的 Subversion,Git 為現在很紅的一套版本控制 Software,底下紀錄在 FreeBSD 如何架設簡易 Git Server。 1. 利用 FreeBSD ports 安裝:
cd /usr/ports/devel/git; make install clean2. 修改 /etc/rc.conf
git_daemon_enable="YES" git_daemon_directory="/path/git/repo" git_daemon_flags="--export-all --syslog --enable=receive-pack --listen=192.168.1.1"注意 git\_daemon\_flags 可以加入 --verbose 參數,以方便 debug 3. 新增使用者 git
pw user add git4. 啟動 git daemon
/usr/local/etc/rc.d/git_daemon start您會發現多出 9418 連接埠,就是成功了 [Read More]

