<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kanru&#039;s 探險日誌 &#187; git</title>
	<atom:link href="http://blog.kanru.info/archives/tag/git/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.kanru.info</link>
	<description>當發現美好的事物時，所要做的第一件事，就是把它分享給所有人</description>
	<lastBuildDate>Sun, 23 May 2010 09:51:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Git branch in bash prompt</title>
		<link>http://blog.kanru.info/archives/550</link>
		<comments>http://blog.kanru.info/archives/550#comments</comments>
		<pubDate>Sat, 13 Dec 2008 12:47:54 +0000</pubDate>
		<dc:creator>kanru</dc:creator>
				<category><![CDATA[小工具]]></category>
		<category><![CDATA[爬網探險]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[prompt]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.kanru.info/?p=550</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.kanru.info/archives/343">之前</a>提過 zsh 有支援在 prompt 上顯示多種 VCS 資訊的功能，不知道 bash 上是否有人寫好同樣支援這麼多種 VCS 的 library，不過目前 git 附帶的 bash completion script 中有提供自訂 PS1 的函式。</p>

<p>只要呼叫 <code>__git_ps1</code> 即可得到目前的 git branch 的格式化輸出，可以自訂 prompt 如下</p>

<p><pre lang="plain">
GITPS1='$(__git_ps1 ":%s ")'
export PS1="\w ${GITPS1}&#92;$ "
</pre></p>

<p>就會顯示如</p>

<p><pre lang="plain">
/usr/src/awesome :next $
</pre></p>

<p>這樣的 prompt</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kanru.info/archives/550/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>為什麼 Git 比 X 好？</title>
		<link>http://blog.kanru.info/archives/525</link>
		<comments>http://blog.kanru.info/archives/525#comments</comments>
		<pubDate>Sat, 06 Dec 2008 00:40:33 +0000</pubDate>
		<dc:creator>kanru</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[小工具]]></category>
		<category><![CDATA[爬網探險]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://blog.kanru.info/?p=525</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>當初一看到這個標題心裡想的是 Git 怎麼拿來跟 X 比？原來這個 X 是指其他 SCM&#8230;</p>

<p><a href="http://whygitisbetterthanx.com/">http://whygitisbetterthanx.com/</a></p>

<p>很多人都注意到了，但是現在有</p>

<p><a href="http://zh-tw.whygitisbetterthanx.com/">http://zh-tw.whygitisbetterthanx.com/</a></p>

<p>囉，小小替 Git 宣傳一下 :p</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kanru.info/archives/525/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>使用 git-svn 整合 git 與 svn</title>
		<link>http://blog.kanru.info/archives/466</link>
		<comments>http://blog.kanru.info/archives/466#comments</comments>
		<pubDate>Sun, 23 Nov 2008 10:03:18 +0000</pubDate>
		<dc:creator>kanru</dc:creator>
				<category><![CDATA[小工具]]></category>
		<category><![CDATA[爬網探險]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.kanru.info/?p=466</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>git 是目前最紅的分散式 VCS 之一，我很喜歡用 git 因為他預設就有許多方便的特性如：</p>

<ul>
<li>git log/diff/help 都有彩色的 pager 可用，不用再自己 pipe 到 less</li>
<li>git log 的格式一目了然，清晰易懂</li>
<li>git bisect/format-patch/shortlog/stash&#8230; 等趁手工具一堆</li>
<li>速度快</li>
</ul>

<p>而 git 不僅僅是 git，他分成高階的命令如 pull/commit 等，還有低階的命令可以直接操作 ref/object，因此有一些 VCS 就是建立在 git 的檔案系統上，運作起來跟 git 截然不同。</p>

<p>git-svn 是一個可以把 svn 當 git 用的工具，就算專案還在用 svn 也可以享受到 git 的便利。以下簡介一下 git-svn 的使用流程。</p>

<p>首先創造一個實驗用的 svn repository：</p>

<p><pre lang="shell">
bob % cd /tmp/test
bob % svnadmin create hello
bob % svn co file:///tmp/test/hello hello-svn
bob % cd hello-svn
bob % svn mkdir branches tags trunk
bob % svn ci -m'Initial dir setup'
</pre></p>

<p>現在我們有一個傳統的 svn repository 了，加點東西進去吧：</p>

<p><pre lang="shell">
bob % cd trunk
bob % echo "printf("hello\n");" > hello.c
bob % svn add hello.c
bob % svn ci -m'My first program <img src='http://blog.kanru.info/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> '
bob % cd ..
bob % svn cp trunk tags/v0.1
bob % svn ci -m'tag v0.1'
</pre></p>

<p>這時候 Bob 已經建好他的程式 v0.1 版，Alice 知道了他的計劃也想加入，於是她用 git-svn 來取出 repository</p>

<p><pre lang="shell">
alice % git svn clone --stdlayout file:///tmp/test/hello hello-git
Initialized empty Git repository in /tmp/test/hello-git/.git/
r1 = 80a0fc18653e8bc7d3784567b1b7024b20fd8c11 (trunk)
    A   hello.c
r2 = 4a80acebb6a41c208f3427498225f829950ee39e (trunk)
Found possible branch point: file:///tmp/test/hello/trunk => file:///tmp/test/hello/tags/v0.1, 1
Found branch parent: (tags/v0.1) 80a0fc18653e8bc7d3784567b1b7024b20fd8c11
Following parent with do_switch
    A   hello.c
Successfully followed parent
r3 = 24ca9410e9ca78ffa3bffa1c9ef574068d128935 (tags/v0.1)
Checked out HEAD:
  file:///tmp/test/hello/tags/v0.1 r3
alice % git reset --hard remotes/trunk
</pre></p>

<p>因為是使用 stdlayout，所以 tag/branch 等會自動對應到 remote branch</p>

<p><pre lang="shell">
alice % cd hello-git
alice % git branch -r
  tags/v0.1
  trunk
</pre></p>

<p>Alice 發現 Bob 原本的程式無法 compile，因此開始修改，改完之後用 <code>git add -p</code> 挑選要 commit 的部份，然後把剩下的部份 stash 起來，最後用 <code>git svn dcommit</code> 提交給 Bob 的 svn repository</p>

<p><pre lang="shell">
alice % edit hello.c
alice % git add -p
alice % git commit -m'Fix everything'
alice % git stash
alice % git svn dcommit
</pre></p>

<p>隔了幾天，Alice 發現 Bob 有更新，因此開始做同步。同時，因為她有一個 local branch，所以在更新完 master 之後，還需要把 fancy branch 跟 master rebase。</p>

<p><pre lang="shell">
alice % git svn fetch
    M   hello.c
r6 = c43134a98f43dc6507deaa7495bfcd2c906aaa30 (trunk)
alice % git svn rebase
First, rewinding head to replay your work on top of it...
Fast-forwarded master to refs/remotes/trunk.
alice % git checkout fancy
alice % git rebase master
First, rewinding head to replay your work on top of it...
Applying: Inital fancy output branch
</pre></p>

<p>以上就是使用 git-svn 時會用到的大部分指令，其餘的就跟操作一般 git 一樣。</p>

<p>各命令的詳細說明可以參考 <a href="http://www.kernel.org/pub/software/scm/git/docs/git-svn.html">git-svn(1)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kanru.info/archives/466/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Display VCS info in prompts</title>
		<link>http://blog.kanru.info/archives/343</link>
		<comments>http://blog.kanru.info/archives/343#comments</comments>
		<pubDate>Sat, 04 Oct 2008 11:58:58 +0000</pubDate>
		<dc:creator>kanru</dc:creator>
				<category><![CDATA[小工具]]></category>
		<category><![CDATA[爬網探險]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[vcs]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://blog.kanru.info/?p=343</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>通常 VCS (Version Control System) 都會在工作目錄底下藏一些特殊目錄用來儲存資訊，如 .svn .git .hg 等，因此我們可以在 shell prompt 上動一些手腳，當我們進到 VCS 工作目錄時，自動顯示相關的訊息在 prompt 上。</p>

<p>而 zsh-beta 4.3.6-dev-0+20080921-1 內建了由 Frank Terbeck 開發的 vcs_info 子系統，可以自動偵測 bzr, cdv, CVS, darcs, git, hg, mtn, p4, svk, svn, tla 等多種 VCS，並設定相關的環境變數可以顯示在 prompt 上。</p>

<p><img src="http://people.debian.org.tw/~koster/blog/2008-09-22-200437_506x113_scrot.png" alt="zsh prompt"/></p>

<p>我的 prompt 設定如下</p>

<p><pre lang="plain">
    autoload -Uz vcs_info &amp;&amp; vcs_info
    zstyle ':vcs_info:<em>' actionformats \
    '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
    zstyle ':vcs_info:</em>' formats       \
    '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
    zstyle ':vcs_info:(sv[nk]|bzr):<em>' branchformat '%b%F{1}:%F{3}%r'
    precmd () { vcs_info }
    EXITCODE="%(?..%?%1v )"
    JOBS="%(1j.%j .)"
    local BLUE="%{^[[1;34m%}"
    local RED="%{^[[1;31m%}"
    local GREEN="%{^[[1;32m%}"
    local CYAN="%{^[[1;36m%}"
    local YELLOW="%{^[[1;33m%}"
    local NO_COLOUR="%{^[[0m%}"
    PROMPT="${RED}${EXITCODE}${CYAN}${JOBS}${YELLOW}%</em> ${RED}%n${BLUE}@%m:${GREEN}%40&lt;...< %B%~%b%&lt;&lt;"'${vcs_info_msg_0_}'"
    ${YELLOW}%# ${NO_COLOUR}"
</pre></pre></p>

<p>詳細的設定請參閱 zshcontrib(3) GATHERING INFORMATION FROM VERSION CONTROL SYSTEMS</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kanru.info/archives/343/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
