十月 11, 2014
» 讓 Git 使用起來更方便的一些 tips


(Full Moon.Taipei)

第一件事是讓 terminal 可以支援 git command 還有 branch name 的自動補齊,不用每次都要記落落長的分支名稱。

1. 下載 autocomplete 的 shell script

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
 
2. 在 ~/.bash_profile 中加入下面的 script

if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi 
 
然後重新載入一下 .bash_profile 就可以了。
   
第二件事是讓 terminal 的 prompt 可以顯示目前是在哪個分支。
方法也很簡單,在 PS1 這個變數中,適當的位置加入 \$(__git_ps1) 就可以了。
像我的設法是:
 
export PS1='\[\e[36;1m\][\h]\[\e[33;1m\]\t \[\e[0m\]\[\e[32;1m\]\w \[\e[0m\]$(__git_ps1 "(%s)")\n$'
 
REF: 
1. http://code-worrier.com/blog/autocomplete-git/
2. http://code-worrier.com/blog/git-branch-in-bash-prompt/
 
 
 
 

七月 29, 2013
» How to build your own 'repo' to Manage project with multiple git repositories



'repo' is a good tool to manage project with multiple git repositories. Its developed to serve the need to manage Android Open Source Project (AOSP), which counts on bunch of open source projects. Then the 'repo' tool is used for chromium and chromium OS (known as open source version of Chrome browser and Chrome OS). Now Mozilla Boot-to-Gecko (B2G, known as Firefox OS) also adpot the 'repo' tool to manage multiple git repositories.

For a short time of experiment, I find its pretty simple to setup your own 'repo' that can help you manage multiple git repositories. Here is my findings.

To install 'repo' command, you can refer to Installing repo.

Make your own repo

All you have to do is:

1. setup an accessible git repository
2. Put a 'default.xml' file in it
3. Use 'repo init' command to access this  git repository.

Done!

Here is the default.xml sample, there are three main tags:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<!-- define hosts -->
<remote name="b2g" fetch="https://github.com/mozilla-b2g/"/>
<!-- default settings -->
<default sync-j="4"/> <!-- projects -->
<project remote="b2g" revision="refs/heads/master" name="gaia" path="."/>
</manifest>
Look at the 'project' tag. It describes that we'd like to sync the 'gaia' repository's 'master' branch from remote 'b2g' host.

Explaination

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
...
</manifest>
The 'default.xml' syntax is wrapped by 'manifest' tag.
It contains three parts of definition:

Hosts

<remote name="b2g" fetch="https://github.com/mozilla-b2g/"/>
'remote' tag is used to define the hosts that we'd like to use in projects.
Note that it's not the actual git URL, but where the git hosted on.
We can specify the actual git URL in 'project' tag.

Projects

<project remote="b2g" revision="refs/heads/master" name="gaia" path="."/>

The file describes that we'll like to sync the 'gaia' repository's 'master' branch from remote 'b2g' host.

The 'revision' path is defined within the original .git folder. To switch to branch like "v1.0.1", we could change  "refs/heads/master" to "refs/heads/v1.0.1".
It's almost the same as we have to do with git command. 

By the way, default.xml itself is in a git repository, so you can specify versions by branch or whatever you like.

Defaults
<default sync-j="4"/>
In default tag we can specify the default values in project tag. ex: revisions, default repositories..., etc.
'sync-j' means with this setting, 'repo' command will download 4 resources at the same time.

The usage 

Create a folder, switch in it, and run the following command:

$ repo init -u https://<your own git URL>.git
Then, fetch the resources with command

$ repo sync
To fetch a branch, run command
 
$ repo init -u https://<your own git URL>.git -b <branch>

Read Git and repo cheatsheet for more details about how git and repo tool work together.  

Sample

Here is a working sample that able you to sync Mozilla Gaia repositorie, and automatically put vendor customization folder into its 'distribution/' sub-folder to ease the customization work.

https://github.com/gasolin/gaia-custom-repo

Update at 7/29:

A workable process elaboration in slide format http://gasolin.github.io/gaia-repo/

十二月 2, 2012
» 使用Git與Github管理軟體開發專案

之前聽聞git這個版本控制時,看到有人介紹github這個服務。 https://github.com/ http://zh-tw.whygitisbetterthanx.com/#github git是個分散式的版本控制軟體。大部分的版本控制軟體都需要一個伺服端,在commit的同時,提交到伺服器上面。git當然也可以集中管理,但是他另外多了分散管理的方式。簡單來說,billy開了一個專案,tom覺得這個專案有意思,他想玩玩看,他可以把整個repo(reoisitories)都clone過去,並且在他那邊自己有一個repo。tom可以自由的對這個repo做各種提交修改,直到他覺得滿意為止。這時候tom可以告訴billy,他改了一些什麼,若billy覺得不錯,可以從tom那邊fetch回去並merge。 由於repo可以綁在寫程式的人身上,不用一定要有中央伺服器的主從架構,

三月 22, 2012
» git diff & patch

git diff --no-prefix > patchfile

patch -p0 < patchfile

» git diff & patch

git diff --no-prefix > patchfile

patch -p0 < patchfile

一月 16, 2008
» rename support

習慣版本控制後寫程式會大膽許多,反正比對修改之處很簡單,復原到特定版本也只是舉手之勞。不過這僅限於納入追蹤控管的內容。大部份的版本控制系統能控管的項目還是有限 (我沒用過商業版,不曉得有沒有比較厲害),例如目錄與更名 (rename) 的控管。

» rename support

習慣版本控制後寫程式會大膽許多,反正比對修改之處很簡單,復原到特定版本也只是舉手之勞。不過這僅限於納入追蹤控管的內容。大部份的版本控制系統能控管的項目還是有限 (我沒用過商業版,不曉得有沒有比較厲害),例如目錄與更名 (rename) 的控管。 有時在開發初期隨手寫幾個測試用的程式,隨後越來越龐大後開始整理並組織現有的程式碼,先不管開發流程的好壞,應該很多人都有類似經驗。不過若是一開始有導入版本控管,接下來就是頭大的問題了。以 cvs 來說,檔案一改名字或改路徑 (整理到特定目錄),history 就會中斷,日後要 diff 也不容易。 後起之秀 svn 雖然可以記錄 snapshot,checkout 特定版本不會掉檔案,印象中一樣不會有 rename 的記錄,只能人眼觀察前後幾個 revision 的檔案變化,但總是比 cvs 方便多了。 Wikipedia 上有一張 比較表 ,其中就包含 rename 項目。我目前有在使用的 svn、hg 和 git 都有支援 rename,但只有 hg 和 git 的記錄上看得到 reanme 的資訊 (svn 很久沒用了,要再確認看看)。rename 時需要用內建指令才會加入記錄:(-n 為測試指令用,不會真的執行動作) $ hg -v mv -n a.c b.c copying a.c to b.c removing a.c 或是 $ git mv -n a.c b.c Checking [...]

biggo.com.tw

A Django site.