<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hant-TW">
	<id>https://jiva.dila.edu.tw/index.php?action=history&amp;feed=atom&amp;title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE</id>
	<title>Pro Git 7.1 Git 配置 - 修訂歷史</title>
	<link rel="self" type="application/atom+xml" href="https://jiva.dila.edu.tw/index.php?action=history&amp;feed=atom&amp;title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE"/>
	<link rel="alternate" type="text/html" href="https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;action=history"/>
	<updated>2026-05-05T12:44:44Z</updated>
	<subtitle>本 Wiki 上此頁面的修訂歷史</subtitle>
	<generator>MediaWiki 1.39.1</generator>
	<entry>
		<id>https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;diff=574&amp;oldid=prev</id>
		<title>imported&gt;Ray：​/* core.autocrlf */</title>
		<link rel="alternate" type="text/html" href="https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;diff=574&amp;oldid=prev"/>
		<updated>2011-06-30T03:24:11Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;core.autocrlf&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hant-TW&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上個修訂&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;於 2011年6月30日 (四) 11:24 的修訂&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l275&quot;&gt;行 275：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;行 275：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$ git config --global core.autocrlf false&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$ git config --global core.autocrlf false&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;core.whitespace&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==core.whitespace==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Git 預先設置了一些選項來探測和修正空白問題，其4種主要選項中的2個預設被打開，另2個被關閉，你可以自由地打開或關閉它們。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Git 預先設置了一些選項來探測和修正空白問題，其4種主要選項中的2個預設被打開，另2個被關閉，你可以自由地打開或關閉它們。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>imported&gt;Ray</name></author>
	</entry>
	<entry>
		<id>https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;diff=573&amp;oldid=prev</id>
		<title>imported&gt;Ray：​/* color.ui */</title>
		<link rel="alternate" type="text/html" href="https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;diff=573&amp;oldid=prev"/>
		<updated>2011-06-30T02:28:14Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;color.ui&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hant-TW&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上個修訂&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;於 2011年6月30日 (四) 10:28 的修訂&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l134&quot;&gt;行 134：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;行 134：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; 你會很少用到 color.ui = always，在大多數情況下，如果你想在被重定向的輸出中插入顏色碼，你能傳遞 --color 標誌給 Git 命令來迫使它這麼做，color.ui = true 應該是你的首選。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; 你會很少用到 color.ui = always，在大多數情況下，如果你想在被重定向的輸出中插入顏色碼，你能傳遞 --color 標誌給 Git 命令來迫使它這麼做，color.ui = true 應該是你的首選。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;color.*&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==&lt;/ins&gt;color.*&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; 想要具體指定哪些命令輸出需要被著色，以及怎樣著色，或者 Git 的版本很老，你就要用到和具體命令有關的顏色配置選項，它們都能被設為 true、false 或 always：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; 想要具體指定哪些命令輸出需要被著色，以及怎樣著色，或者 Git 的版本很老，你就要用到和具體命令有關的顏色配置選項，它們都能被設為 true、false 或 always：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>imported&gt;Ray</name></author>
	</entry>
	<entry>
		<id>https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;diff=572&amp;oldid=prev</id>
		<title>imported&gt;Ray 於 2011年6月23日 (四) 04:03</title>
		<link rel="alternate" type="text/html" href="https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;diff=572&amp;oldid=prev"/>
		<updated>2011-06-23T04:03:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;amp;diff=572&amp;amp;oldid=571&quot;&gt;顯示變更&lt;/a&gt;</summary>
		<author><name>imported&gt;Ray</name></author>
	</entry>
	<entry>
		<id>https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;diff=571&amp;oldid=prev</id>
		<title>imported&gt;Ray：​新頁面: 如第一章所言，用 git config 配置 Git，要做的第一件事就是設置名字和郵箱地址：  &lt;syntaxhighlight lang=&quot;XML&quot;&gt; $ git config --global user.name &quot;John Doe&quot; $ git config --global user.em...</title>
		<link rel="alternate" type="text/html" href="https://jiva.dila.edu.tw/index.php?title=Pro_Git_7.1_Git_%E9%85%8D%E7%BD%AE&amp;diff=571&amp;oldid=prev"/>
		<updated>2011-06-23T01:42:33Z</updated>

		<summary type="html">&lt;p&gt;新頁面: 如第一章所言，用 git config 配置 Git，要做的第一件事就是設置名字和郵箱地址：  &amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt; $ git config --global user.name &amp;quot;John Doe&amp;quot; $ git config --global user.em...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新頁面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;如第一章所言，用 git config 配置 Git，要做的第一件事就是設置名字和郵箱地址：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
$ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
$ git config --global user.email johndoe@example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
從現在開始，你會瞭解到一些類似以上但更為有趣的設置選項來自訂 Git。&lt;br /&gt;
&lt;br /&gt;
先過一遍第一章中提到的 Git 配置細節。Git 使用一系列的設定檔來儲存你定義的偏好，它首先會查找 /etc/gitconfig 檔，該檔含有：對系統上所有使用者以及他們所擁有的倉庫都生效的配置值（譯注：gitconfig 是全域設定檔）， 如果傳遞 --system 選項給 git config 命令， Git 會讀寫這個檔。&lt;br /&gt;
&lt;br /&gt;
接下來 Git 會查找每個用戶的 ~/.gitconfig 檔，你能傳遞 --global 選項讓 Git 讀寫該檔。&lt;br /&gt;
&lt;br /&gt;
最後 Git 會查找由用戶定義的各個庫中 Git 目錄下的設定檔（.git/config），該文件中的值只對該庫有效。以上闡述的三層配置從一般到特殊層層推進，如果定義的值有衝突，以後面層中定義的為准，例如：在 .git/config 和 /etc/gitconfig 的較量中， .git/config 取得了勝利。雖然你也可以直接手動編輯這些設定檔，但是執行 git config 命令將會來得簡單些。&lt;br /&gt;
&lt;br /&gt;
=用戶端基本配置=&lt;br /&gt;
&lt;br /&gt;
Git 能夠識別的配置項被分為了兩大類：用戶端和伺服器端，其中大部分基於你個人工作偏好，屬於用戶端配置。儘管有數不盡的選項，但我只闡述其中經常使用、或者會對你的工作流產生巨大影響的選項，如果你想觀察你當前的 Git 能識別的選項清單，請執行&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
$ git config --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
git config 的手冊頁（譯注：以 man 命令的顯示方式）非常細緻地羅列了所有可用的配置項。&lt;br /&gt;
&lt;br /&gt;
==core.editor==&lt;br /&gt;
&lt;br /&gt;
Git 預設會調用你的環境變數 editor 定義的值作為文字編輯器，如果沒有定義的話，會調用 Vi 來創建和編輯提交以及標籤資訊，你可以使用core.editor 改變預設編輯器：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
$ git config --global core.editor emacs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
現在無論你的環境變數 editor 被定義成什麼，Git 都會調用 Emacs 編輯資訊。&lt;br /&gt;
&lt;br /&gt;
==commit.template==&lt;br /&gt;
&lt;br /&gt;
如果把此項指定為你系統上的一個檔，當你提交的時候，Git 會預設使用該檔定義的內容。例如：你創建了一個範本檔 $HOME/.gitmessage.txt，它看起來像這樣：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
subject line&lt;br /&gt;
&lt;br /&gt;
what happened&lt;br /&gt;
&lt;br /&gt;
[ticket: X]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
設置 commit.template，當執行 git commit 時，Git 會在你的編輯器中顯示以上的內容，設置 commit.template 如下：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
$ git config --global commit.template $HOME/.gitmessage.txt&lt;br /&gt;
$ git commit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
然後當你提交時，在編輯器中顯示的提交資訊如下：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
subject line&lt;br /&gt;
&lt;br /&gt;
what happened&lt;br /&gt;
&lt;br /&gt;
[ticket: X]&lt;br /&gt;
# Please enter the commit message for your changes. Lines starting&lt;br /&gt;
# with '#' will be ignored, and an empty message aborts the commit.&lt;br /&gt;
# On branch master&lt;br /&gt;
# Changes to be committed:&lt;br /&gt;
#   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
#&lt;br /&gt;
# modified:   lib/test.rb&lt;br /&gt;
#&lt;br /&gt;
~&lt;br /&gt;
~&lt;br /&gt;
&amp;quot;.git/COMMIT_EDITMSG&amp;quot; 14L, 297C&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
如果你有特定的策略要運用在提交資訊上，在系統上創建一個範本檔，設置 Git 預設使用它，這樣當提交時，你的策略每次都會被運用。&lt;br /&gt;
&lt;br /&gt;
==core.pager==&lt;br /&gt;
&lt;br /&gt;
core.pager 指定 Git 執行諸如 log、diff 等所使用的分頁器，你能設置成用 more 或者任何你喜歡的分頁器（預設用的是 less）， 當然你也可以什麼都不用，設置空字串：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
$ git config --global core.pager ''&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
這樣不管命令的輸出量多少，都會在一頁顯示所有內容。&lt;br /&gt;
&lt;br /&gt;
==user.signingkey==&lt;br /&gt;
&lt;br /&gt;
如果你要創建經簽署的含附注的標籤（正如第二章所述），那麼把你的 GPG 簽署金鑰設置為配置項會更好，設置金鑰 ID 如下：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
$ git config --global user.signingkey &amp;lt;gpg-key-id&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
現在你能夠簽署標籤，從而不必每次執行 git tag 命令時定義金鑰：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
$ git tag -s &amp;lt;tag-name&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==core.excludesfile==&lt;br /&gt;
&lt;br /&gt;
正如第二章所述，你能在專案庫的 .gitignore 檔裡頭用模式來定義那些無需納入 Git 管理的檔，這樣它們不會出現在未跟蹤列表，也不會在你執行 git add 後被暫存。然而，如果你想用專案庫之外的檔來定義那些需被忽略的檔的話，用 core.excludesfile 通知 Git 該檔所處的位置，檔內容和 .gitignore 類似。&lt;br /&gt;
&lt;br /&gt;
==help.autocorrect==&lt;br /&gt;
&lt;br /&gt;
該配置項只在 Git 1.6.1 及以上版本有效，假如你在 Git 1.6 中錯打了一條命令，會顯示：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
$ git com&lt;br /&gt;
git: 'com' is not a git-command. See 'git --help'.&lt;br /&gt;
&lt;br /&gt;
Did you mean this?&lt;br /&gt;
     commit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
如果你把 help.autocorrect 設置成1（譯注：啟動自動修正），那麼在只有一個命令被模糊匹配到的情況下，Git 會自動運行該命令。&lt;br /&gt;
&lt;br /&gt;
=Git 中的著色=&lt;br /&gt;
&lt;br /&gt;
Git 能夠為輸出到你終端的內容著色，以便你可以憑直觀進行快速、簡單地分析，有許多選項能供你使用以符合你的偏好。&lt;br /&gt;
&lt;br /&gt;
==color.ui==&lt;br /&gt;
&lt;br /&gt;
Git 會按照你的需要，自動為大部分的輸出加上顏色，你能明確地規定哪些需要著色、以及怎樣著色，設置 color.ui 為 true 來打開所有的預設終端著色。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
$ git config --global color.ui true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
設置好以後，當輸出到終端時，Git 會為之加上顏色。其他的參數還有 false 和 always，false 意味著不為輸出著色，而 always 則表明在任何情況下都要著色，即使 Git 命令被重定向到文件或管道。Git 1.5.5 版本引進了此項配置，如果你擁有的版本更老，你必須對顏色有關選項各自進行詳細地設置。&lt;br /&gt;
&lt;br /&gt;
你會很少用到 color.ui = always，在大多數情況下，如果你想在被重定向的輸出中插入顏色碼，你能傳遞 --color 標誌給 Git 命令來迫使它這麼做，color.ui = true 應該是你的首選。&lt;br /&gt;
&lt;br /&gt;
color.*&lt;br /&gt;
&lt;br /&gt;
想要具體到哪些命令輸出需要被著色以及怎樣著色或者 Git 的版本很老，你就要用到和具體命令有關的顏色配置選項，它們都能被置為true、false或always：&lt;br /&gt;
&lt;br /&gt;
color.branch&lt;br /&gt;
color.diff&lt;br /&gt;
color.interactive&lt;br /&gt;
color.status&lt;br /&gt;
除此之外，以上每個選項都有子選項，可以被用來覆蓋其父設置，以達到為輸出的各個部分著色的目的。例如，讓diff輸出的改變資訊以粗體、藍色前景和黑色背景的形式顯示：&lt;br /&gt;
&lt;br /&gt;
$ git config --global color.diff.meta “blue black bold”&lt;br /&gt;
你能設置的顏色值如：normal、black、red、green、yellow、blue、magenta、cyan、white，正如以上例子設置的粗體屬性，想要設置字體屬性的話，可以選擇如：bold、dim、ul、blink、reverse。&lt;br /&gt;
&lt;br /&gt;
如果你想配置子選項的話，可以參考git config幫助頁。&lt;br /&gt;
&lt;br /&gt;
外部的合併與比較工具&lt;br /&gt;
&lt;br /&gt;
雖然 Git 自己實現了diff,而且到目前為止你一直在使用它，但你能夠用一個外部的工具替代它，除此以外，你還能用一個圖形化的工具來合併和解決衝突從而不必自己手動解決。有一個不錯且免費的工具可以被用來做比較和合併工作，它就是P4Merge（譯注：Perforce圖形化合並工具），我會展示它的安裝過程。&lt;br /&gt;
&lt;br /&gt;
P4Merge可以在所有主流平臺上運行，現在開始大膽嘗試吧。對於向你展示的例子，在Mac和Linux系統上，我會使用路徑名，在Windows上，/usr/local/bin應該被改為你環境中的可執行路徑。&lt;br /&gt;
&lt;br /&gt;
下載P4Merge：&lt;br /&gt;
&lt;br /&gt;
http://www.perforce.com/perforce/downloads/component.html&lt;br /&gt;
首先把你要運行的命令放入外部包裝腳本中，我會使用Mac系統上的路徑來指定該腳本的位置，在其他系統上，它應該被放置在二進位檔案p4merge所在的目錄中。創建一個merge包裝腳本，名字叫作extMerge，讓它帶參數調用p4merge二進位檔案：&lt;br /&gt;
&lt;br /&gt;
$ cat /usr/local/bin/extMerge&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
/Applications/p4merge.app/Contents/MacOS/p4merge $*&lt;br /&gt;
diff包裝腳本首先確定傳遞過來7個參數，隨後把其中2個傳遞給merge包裝腳本，預設情況下， Git 傳遞以下參數給diff：&lt;br /&gt;
&lt;br /&gt;
path old-file old-hex old-mode new-file new-hex new-mode&lt;br /&gt;
由於你僅僅需要old-file和new-file參數，用diff包裝腳本來傳遞它們吧。&lt;br /&gt;
&lt;br /&gt;
$ cat /usr/local/bin/extDiff &lt;br /&gt;
#!/bin/sh&lt;br /&gt;
[ $# -eq 7 ] &amp;amp;&amp;amp; /usr/local/bin/extMerge &amp;quot;$2&amp;quot; &amp;quot;$5&amp;quot;&lt;br /&gt;
確認這兩個腳本是可執行的：&lt;br /&gt;
&lt;br /&gt;
$ sudo chmod +x /usr/local/bin/extMerge &lt;br /&gt;
$ sudo chmod +x /usr/local/bin/extDiff&lt;br /&gt;
現在來配置使用你自訂的比較和合併工具吧。這需要許多自訂設置：merge.tool通知 Git 使用哪個合併工具；mergetool.*.cmd規定命令運行的方式；mergetool.trustExitCode會通知 Git 程式的退出是否指示合併操作成功；diff.external通知 Git 用什麼命令做比較。因此，你能運行以下4條配置命令：&lt;br /&gt;
&lt;br /&gt;
$ git config --global merge.tool extMerge&lt;br /&gt;
$ git config --global mergetool.extMerge.cmd \&lt;br /&gt;
    'extMerge &amp;quot;$BASE&amp;quot; &amp;quot;$LOCAL&amp;quot; &amp;quot;$REMOTE&amp;quot; &amp;quot;$MERGED&amp;quot;'&lt;br /&gt;
$ git config --global mergetool.trustExitCode false&lt;br /&gt;
$ git config --global diff.external extDiff&lt;br /&gt;
或者直接編輯~/.gitconfig文件如下：&lt;br /&gt;
&lt;br /&gt;
[merge]&lt;br /&gt;
  tool = extMerge&lt;br /&gt;
[mergetool &amp;quot;extMerge&amp;quot;]&lt;br /&gt;
  cmd = extMerge &amp;quot;$BASE&amp;quot; &amp;quot;$LOCAL&amp;quot; &amp;quot;$REMOTE&amp;quot; &amp;quot;$MERGED&amp;quot;&lt;br /&gt;
  trustExitCode = false&lt;br /&gt;
[diff]&lt;br /&gt;
  external = extDiff&lt;br /&gt;
設置完畢後，運行diff命令：&lt;br /&gt;
&lt;br /&gt;
$ git diff 32d1776b1^ 32d1776b1&lt;br /&gt;
命令列居然沒有發現diff命令的輸出，其實，Git 調用了剛剛設置的P4Merge，它看起來像圖7-1這樣：&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Figure 7-1. P4Merge.&lt;br /&gt;
當你設法合併兩個分支，結果卻有衝突時，運行git mergetool，Git 會調用P4Merge讓你通過圖形介面來解決衝突。&lt;br /&gt;
&lt;br /&gt;
設置包裝腳本的好處是你能簡單地改變diff和merge工具，例如把extDiff和extMerge改成KDiff3，要做的僅僅是編輯extMerge指令檔：&lt;br /&gt;
&lt;br /&gt;
$ cat /usr/local/bin/extMerge&lt;br /&gt;
#!/bin/sh	&lt;br /&gt;
/Applications/kdiff3.app/Contents/MacOS/kdiff3 $*&lt;br /&gt;
現在 Git 會使用KDiff3來做比較、合併和解決衝突。&lt;br /&gt;
&lt;br /&gt;
Git預先設置了許多其他的合併和解決衝突的工具，而你不必設置cmd。可以把合併工具設置為：kdiff3、opendiff、tkdiff、meld、xxdiff、emerge、vimdiff、gvimdiff。如果你不想用到KDiff3的所有功能，只是想用它來合併，那麼kdiff3正符合你的要求，運行：&lt;br /&gt;
&lt;br /&gt;
$ git config --global merge.tool kdiff3&lt;br /&gt;
如果運行了以上命令，沒有設置extMerge和extDiff檔，Git 會用KDiff3做合併，讓通常內設的比較工具來做比較。&lt;br /&gt;
&lt;br /&gt;
格式化與空白&lt;br /&gt;
&lt;br /&gt;
格式化與空白是許多開發人員在協作時，特別是在跨平臺情況下，遇到的令人頭疼的細小問題。由於編輯器的不同或者Windows程式師在跨平臺項目中的檔行尾加入了回車分行符號，一些細微的空格變化會不經意地進入大家合作的工作或提交的補丁中。不用怕，Git 的一些配置選項會説明你解決這些問題。&lt;br /&gt;
&lt;br /&gt;
core.autocrlf&lt;br /&gt;
&lt;br /&gt;
假如你正在Windows上寫程式，又或者你正在和其他人合作，他們在Windows上程式設計，而你卻在其他系統上，在這些情況下，你可能會遇到行尾結束符問題。這是因為Windows使用回車和換行兩個字元來結束一行，而Mac和Linux只使用換行一個字元。雖然這是小問題，但它會極大地擾亂跨平臺協作。&lt;br /&gt;
&lt;br /&gt;
Git可以在你提交時自動地把行結束符CRLF轉換成LF，而在簽出代碼時把LF轉換成CRLF。用core.autocrlf來打開此項功能，如果是在Windows系統上，把它設置成true，這樣當簽出代碼時，LF會被轉換成CRLF：&lt;br /&gt;
&lt;br /&gt;
$ git config --global core.autocrlf true&lt;br /&gt;
Linux或Mac系統使用LF作為行結束符，因此你不想 Git 在簽出檔時進行自動的轉換；當一個以CRLF為行結束符的檔不小心被引入時你肯定想進行修正，把core.autocrlf設置成input來告訴 Git 在提交時把CRLF轉換成LF，簽出時不轉換：&lt;br /&gt;
&lt;br /&gt;
$ git config --global core.autocrlf input&lt;br /&gt;
這樣會在Windows系統上的簽出檔中保留CRLF，會在Mac和Linux系統上，包括倉庫中保留LF。&lt;br /&gt;
&lt;br /&gt;
如果你是Windows程式師，且正在開發僅運行在Windows上的專案，可以設置false取消此功能，把回車符記錄在庫中：&lt;br /&gt;
&lt;br /&gt;
$ git config --global core.autocrlf false&lt;br /&gt;
core.whitespace&lt;br /&gt;
&lt;br /&gt;
Git預先設置了一些選項來探測和修正空白問題，其4種主要選項中的2個預設被打開，另2個被關閉，你可以自由地打開或關閉它們。&lt;br /&gt;
&lt;br /&gt;
預設被打開的2個選項是trailing-space和space-before-tab，trailing-space會查找每行結尾的空格，space-before-tab會查找每行開頭的定位字元前的空格。&lt;br /&gt;
&lt;br /&gt;
預設被關閉的2個選項是indent-with-non-tab和cr-at-eol，indent-with-non-tab會查找8個以上空格（非定位字元）開頭的行，cr-at-eol讓 Git 知道行尾回車符是合法的。&lt;br /&gt;
&lt;br /&gt;
設置core.whitespace，按照你的意圖來打開或關閉選項，選項以逗號分割。通過逗號分割的鏈中去掉選項或在選項前加-來關閉，例如，如果你想要打開除了cr-at-eol之外的所有選項：&lt;br /&gt;
&lt;br /&gt;
$ git config --global core.whitespace \&lt;br /&gt;
    trailing-space,space-before-tab,indent-with-non-tab&lt;br /&gt;
當你運行git diff命令且為輸出著色時，Git 探測到這些問題，因此你也許在提交前能修復它們，當你用git apply打補丁時同樣也會從中受益。如果正準備運用的補丁有特別的空白問題，你可以讓 Git 發警告：&lt;br /&gt;
&lt;br /&gt;
$ git apply --whitespace=warn &amp;lt;patch&amp;gt;&lt;br /&gt;
或者讓 Git 在打上補丁前自動修正此問題：&lt;br /&gt;
&lt;br /&gt;
$ git apply --whitespace=fix &amp;lt;patch&amp;gt;&lt;br /&gt;
這些選項也能運用於衍合。如果提交了有空白問題的檔但還沒推送到上流，你可以運行帶有--whitespace=fix選項的rebase來讓Git在重寫補丁時自動修正它們。&lt;br /&gt;
&lt;br /&gt;
伺服器端配置&lt;br /&gt;
&lt;br /&gt;
Git伺服器端的配置選項並不多，但仍有一些饒有生趣的選項值得你一看。&lt;br /&gt;
&lt;br /&gt;
receive.fsckObjects&lt;br /&gt;
&lt;br /&gt;
Git預設情況下不會在推送期間檢查所有物件的一致性。雖然會確認每個物件的有效性以及是否仍然匹配SHA-1核對總和，但 Git 不會在每次推送時都檢查一致性。對於 Git 來說，庫或推送的檔越大，這個操作代價就相對越高，每次推送會消耗更多時間，如果想在每次推送時 Git 都檢查一致性，設置 receive.fsckObjects 為true來強迫它這麼做：&lt;br /&gt;
&lt;br /&gt;
$ git config --system receive.fsckObjects true&lt;br /&gt;
現在 Git 會在每次推送生效前檢查庫的完整性，確保有問題的用戶端沒有引入破壞性的資料。&lt;br /&gt;
&lt;br /&gt;
receive.denyNonFastForwards&lt;br /&gt;
&lt;br /&gt;
如果對已經被推送的提交歷史做衍合，繼而再推送，又或者以其它方式推送一個提交歷史至遠端分支，且該提交歷史沒在這個遠端分支中，這樣的推送會被拒絕。這通常是個很好的禁止策略，但有時你在做衍合併確定要更新遠端分支，可以在push命令後加-f標誌來強制更新。&lt;br /&gt;
&lt;br /&gt;
要禁用這樣的強制更新功能，可以設置receive.denyNonFastForwards：&lt;br /&gt;
&lt;br /&gt;
$ git config --system receive.denyNonFastForwards true&lt;br /&gt;
稍後你會看到，用伺服器端的接收鉤子也能達到同樣的目的。這個方法可以做更細緻的控制，例如：禁用特定的用戶做強制更新。&lt;br /&gt;
&lt;br /&gt;
receive.denyDeletes&lt;br /&gt;
&lt;br /&gt;
規避denyNonFastForwards策略的方法之一就是使用者刪除分支，然後推回新的引用。在更新的 Git 版本中（從1.6.1版本開始），把receive.denyDeletes設置為true：&lt;br /&gt;
&lt;br /&gt;
$ git config --system receive.denyDeletes true&lt;br /&gt;
這樣會在推送過程中阻止刪除分支和標籤 — 沒有使用者能夠這麼做。要刪除遠端分支，必須從伺服器手動刪除引用檔。通過用戶存取控制清單也能這麼做，在本章結尾將會介紹這些有趣的方式。&lt;/div&gt;</summary>
		<author><name>imported&gt;Ray</name></author>
	</entry>
</feed>