<?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>林光生活兩光過 &#187; Git</title>
	<atom:link href="http://blog.yzlin.org/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.yzlin.org</link>
	<description>人生就該悠閒地過，忠實地記錄下人生的軌跡</description>
	<lastBuildDate>Thu, 21 Jan 2010 15:46:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Git &#8211; How to edit incorrect commit messages?</title>
		<link>http://blog.yzlin.org/2010/01/21/96/</link>
		<comments>http://blog.yzlin.org/2010/01/21/96/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 15:44:36 +0000</pubDate>
		<dc:creator>yzlin</dc:creator>
				<category><![CDATA[工具]]></category>
		<category><![CDATA[電腦技術]]></category>
		<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://blog.yzlin.org/?p=96</guid>
		<description><![CDATA[一般來說，要修改最近一次的 commit，常見的方式有：

git revert &#38; git commit：這個方式很直覺，直接 revert 回上一個版本，然後重新 commit，不過因為 revert 會連這次 commit 中的記錄也消掉，這樣太麻煩了，我只是想改個 commit message 而已啊！XD
git commit &#8211;amend：這個可以直接翻譯成&#8221;重新修改最近這次 commit&#8221;，其相當於
$ git reset &#8211;soft HEAD^
$ &#8230; do something else to come up with the right tree &#8230;
$ git commit -c ORIG_HEAD


然而，對於要修改較舊的 commit，上面的做法可能就不適用了，據我所知目前的做法有兩種，第一種是使用 git rebase：
git rebase &#8211;interactive &#60;after-this-commit-id&#62;

這樣會跳出介面讓你選擇想要修改的 commit，選擇完畢後，會由舊到新依序停在每個你所選擇的 commit，然後利用
git commit &#8211;amend
來修改該次的 commit，再搭配
git rebase &#8211;continue
來繼續下一個選擇的 commit。這種做法很方便，也可以快速地達到目的，因為是用 rebase，修改 commit [...]]]></description>
			<content:encoded><![CDATA[<p>一般來說，要修改最近一次的 commit，常見的方式有：</p>
<ul>
<li>git revert &amp; git commit：這個方式很直覺，直接 revert 回上一個版本，然後重新 commit，不過因為 revert 會連這次 commit 中的記錄也消掉，這樣太麻煩了，我只是想改個 commit message 而已啊！XD</li>
<li>git commit &#8211;amend：這個可以直接翻譯成&#8221;重新修改最近這次 commit&#8221;，其相當於<br />
<blockquote><p>$ git reset &#8211;soft HEAD^<br />
$ &#8230; do something else to come up with the right tree &#8230;<br />
$ git commit -c ORIG_HEAD</p></blockquote>
</li>
</ul>
<p>然而，對於要修改較舊的 commit，上面的做法可能就不適用了，據我所知目前的做法有兩種，第一種是使用 git rebase：</p>
<blockquote><p>git rebase &#8211;interactive &lt;after-this-commit-id&gt;
</p></blockquote>
<p>這樣會跳出介面讓你選擇想要修改的 commit，選擇完畢後，會由舊到新依序停在每個你所選擇的 commit，然後利用</p>
<blockquote><p>git commit &#8211;amend</p></blockquote>
<p>來修改該次的 commit，再搭配</p>
<blockquote><p>git rebase &#8211;continue</p></blockquote>
<p>來繼續下一個選擇的 commit。這種做法很方便，也可以快速地達到目的，因為是用 rebase，修改 commit message 倒是還好，如果有修改到 content，可能就要注意一下 conflict &amp; merge 的問題了。另外，這個方式對某個我試的結果，對於修改 first commit 會沒輒。這時候可能要使用另一種比較麻煩的做法了。</p>
<p>第二種做法是利用一個由要修改的 commit 產生一個 target commit (在另一個 branch 中)，同樣搭配 git commit &#8211;amend 來修改，最後利用 git rebase 來覆蓋原本的 commit：</p>
<blockquote><p># tag the source commit so we can reference it<br />
git tag source-commit &lt;source-commit-id&gt;<br />
# checkout on its own branch<br />
git checkout -b fake-branch source-commit<br />
# amend the commit<br />
git commit &#8211;amend<br />
# after you changed the commit message, checkout the original branch<br />
git checkout &lt;original-branch&gt;<br />
# and rebase it onto the source commit<br />
git rebase &#8211;onto fake-branch source-commit<br />
# then nuke the temporary branch and tag we created<br />
git branch -d fake-branch<br />
git tag -d source-commit</p></blockquote>
<p>就看情形使用了，大部份還是用第一種做法，不過一開始就把 commit message 寫好最省事 XD</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yzlin.org/2010/01/21/96/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
