<?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://wangcongming.info/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://wangcongming.info</link>
	<description>灵 动 生 活　　点 滴 感 悟</description>
	<lastBuildDate>Tue, 27 Dec 2011 06:23:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Git 系列之四：Git 进阶功能</title>
		<link>http://wangcongming.info/2010/07/git-%e7%b3%bb%e5%88%97%e4%b9%8b%e5%9b%9b%ef%bc%9agit-%e8%bf%9b%e9%98%b6%e5%8a%9f%e8%83%bd/</link>
		<comments>http://wangcongming.info/2010/07/git-%e7%b3%bb%e5%88%97%e4%b9%8b%e5%9b%9b%ef%bc%9agit-%e8%bf%9b%e9%98%b6%e5%8a%9f%e8%83%bd/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 07:38:59 +0000</pubDate>
		<dc:creator>Wang Congming</dc:creator>
				<category><![CDATA[Geek Tweak]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://wangcongming.info/?p=246</guid>
		<description><![CDATA[【TIP】在我们的《Windows 下 Git 配置与使用指南》 中，有介绍大家使用 $ git go 命令。其实，这并非 Git 的原生命令，它是我们自定义的一个 alias（别名），由 $git add、$git commit、$git push 和 $git pull 四个命令组合而成。待熟悉之后，你可以直接使用这些原生命令，或者自定义更适合自己的 alias。 add 添加新文件到 Git 代码仓库的索引中 $ git add filename mv 移动或重命名文件 $ git mv old-filename new-filename rm 从工作目录和 Git 代码索引中删除文件 $ git rm filename status 查看目前工作目录的代码状态，自上次提交以来的添加、修改和删除等 $ git status diff 查看自上次提交以来，本地代码改动的具体情况 $ git diff commit [...]]]></description>
			<content:encoded><![CDATA[<p>【TIP】在我们的<a href="http://wangcongming.info/2010/07/31/git-%E7%B3%BB%E5%88%97%E4%B9%8B%E4%B8%89%EF%BC%9Awindows-%E4%B8%8B-git-%E9%85%8D%E7%BD%AE%E4%B8%8E%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/">《Windows 下 Git 配置与使用指南》</a> 中，有介绍大家使用 $ git go 命令。其实，这并非 Git 的原生命令，它是我们自定义的一个 alias（别名），由 $git  add、$git commit、$git push 和 $git pull  四个命令组合而成。待熟悉之后，你可以直接使用这些原生命令，或者自定义更适合自己的 alias。</p>
<h2 style="margin-top: 40px; font-weight: bold;">add</h2>
<p>添加新文件到 Git 代码仓库的索引中</p>
<pre>$ git add filename</pre>
<h2 style="margin-top: 40px; font-weight: bold;">mv</h2>
<p>移动或重命名文件</p>
<pre>$ git mv old-filename new-filename</pre>
<h2 style="margin-top: 40px; font-weight: bold;">rm</h2>
<p>从工作目录和 Git 代码索引中删除文件</p>
<pre>$ git rm filename</pre>
<h2 style="margin-top: 40px; font-weight: bold;">status</h2>
<p>查看目前工作目录的代码状态，自上次提交以来的添加、修改和删除等</p>
<pre>$ git status</pre>
<h2 style="margin-top: 40px; font-weight: bold;">diff</h2>
<p>查看自上次提交以来，本地代码改动的具体情况</p>
<pre>$ git diff</pre>
<h2 style="margin-top: 40px; font-weight: bold;">commit</h2>
<p>提交修改的代码（只是提交到本地的代码库，不会推送到服务器）</p>
<pre>$ git commit -am '修改说明'</pre>
<p>如果觉得刚提交的“修改说明”写得不够好，可输入以下命令调整</p>
<pre>$ git commit --amend</pre>
<h2 style="margin-top: 40px; font-weight: bold;">push</h2>
<p>将自上次 push 以来的，本地历次 commit，推送到服务器</p>
<p>结合我们的实际，应该这样写：</p>
<pre>$ git push origin master:your-id</pre>
<p>其中，master 是本地的分支名；your-id 填你在服务器上的 id，服务器的版本库里会有以你的 id 为名称的分支。</p>
<h2 style="margin-top: 40px; font-weight: bold;">pull</h2>
<p>将别人推送到服务器的代码，拉到你的机器里</p>
<pre>$ git pull</pre>
<h2 style="margin-top: 40px; font-weight: bold;">log</h2>
<p>查看修改记录，含作者、时间、修改说明等</p>
<pre>$ git log</pre>
<h2 style="margin-top: 40px; font-weight: bold;">show</h2>
<p>显示具体的代码改动情况</p>
<h3 style="font-weight: normal;">显示最后一次 commit 修改的内容：</h3>
<pre>$ git show</pre>
<h3 style="font-weight: normal;">显示指定 commit 修改的内容：</h3>
<p>【TIP】git log 命令中，每条 commit 会有一长长的字符串，此即 commid id，取其前面五六位即可。</p>
<pre>$ git show commit-id</pre>
<h2 style="margin-top: 40px; font-weight: bold;">branch</h2>
<p>分支管理</p>
<h3 style="font-weight: normal;">列出所有分支（当前所在分支前会有“*”号）：</h3>
<pre>$ git branch</pre>
<h3 style="font-weight: normal;">新建分支：</h3>
<pre>$ git branch 新分支名</pre>
<h3 style="font-weight: normal;">删除分支：</h3>
<pre>$ git branch -d 欲删除的分支名</pre>
<p>【注意！】不要把 &#8216;-d&#8217; 写成了 &#8216;-D&#8217;，危险！</p>
<ul>
<li>-d：要求：被删除分支的所有修改，已经合并到当前分支；</li>
<li>-D：直接删除，未合并的代码，将被丢弃！</li>
</ul>
<h2 style="margin-top: 40px; font-weight: bold;">checkout</h2>
<h3 style="font-weight: normal;">恢复某个已修改的文件（撤销未提交的修改）：</h3>
<pre>$ git checkout file-name</pre>
<h3 style="font-weight: normal;">切换到另外的分支，进行开发：</h3>
<pre>$ git checkout branch-name</pre>
<p>【注意！】该命令可能伴随大量的文件增删/修改。Windows 下，改动已被占用的文件可能会被拒绝，导致版本库出现严重问题。如果确实要这样做，安全起见，最好先注销一次。</p>
<h2 style="margin-top: 40px; font-weight: bold;">merge</h2>
<p>合并指定分支到当前分支：</p>
<pre>$ git merge branch-name</pre>
<h2 style="margin-top: 40px; font-weight: bold;">revert</h2>
<p>还原已提交的修改（已经提交过的修改，可以反悔～）</p>
<h3 style="font-weight: normal;">还原最近一次提交的修改：</h3>
<pre>$ git revert HEAD</pre>
<h3 style="font-weight: normal;">还原指定版本的修改：</h3>
<pre>$ git revert commit-id</pre>
<h2 style="margin-top: 40px; font-weight: bold;">stash</h2>
<p>先将未提交的修改暂存起来，接着清除所有改动，使之与没修改时一样。</p>
<p>若你正在开发功能 A，又需立即去开发功能 B。A 的代码正改到一半，未认真整理，你不想立即提交。此时……请呼叫 stash ～。</p>
<h3 style="font-weight: normal;">它会使你所有未提交的修改瞬间不见了：</h3>
<pre>$ git stash</pre>
<h3 style="font-weight: normal;">它会使刚刚不见了的修改，瞬间又回来了：</h3>
<pre>$ git stash pop</pre>
<p style="margin-top: 40px;">【TIP】以上命令皆有更多参数，另有一些 Git 命令我们此处没有介绍。但是，这已足令你使用 Git 时游刃有余，你会觉得，Git 简直是一件神器！:-)</p>
<p>【TIP】&#8217;$ git help&#8217; 与 &#8216;$ git help 命令名&#8217; 会在你需要的时候，无私地帮助你。:-)</p>
<h2 style="margin-top: 40px; font-weight: bold;">附：git push 失败的解决办法</h2>
<p>假设执行操作：</p>
<pre>1. 修改代码
2. git commit
3. git push</pre>
<p>此时 push 失败（错误提示：! [rejected]        master -&gt; master (non-fast-forward) ）</p>
<p>解决办法：</p>
<pre>$ git pull</pre>
<p>若成功，则：</p>
<pre>$ git push origin master:your-id</pre>
<p>完事。</p>
<p>若失败（提示：CONFLICT (content): Merge conflict in 文件名），则：</p>
<p>冲突的文件会有类似下面的代码块：</p>
<pre>&lt;&lt;&lt;&lt;HEAD
你修改的代码
============
其他人修改的代码
&gt;&gt;&gt;&gt;&gt;commit id of others'</pre>
<p>考虑你和他人对代码的修改，更新成合适的内容，并删除 &lt;&lt;&lt;、===、&gt;&gt;&gt; 3行标记符号，保存文件。</p>
<pre>$ git commit -am "resolve conflict"
$ git push origin master:your-id</pre>
<p>更详细的说明，可以阅读 $git push &#8211;help 该文档的 NOTE ABOUT FAST-FORWARDS 一节。</p>
]]></content:encoded>
			<wfw:commentRss>http://wangcongming.info/2010/07/git-%e7%b3%bb%e5%88%97%e4%b9%8b%e5%9b%9b%ef%bc%9agit-%e8%bf%9b%e9%98%b6%e5%8a%9f%e8%83%bd/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Git 系列之三：Windows 下 Git 配置与使用指南</title>
		<link>http://wangcongming.info/2010/07/git-%e7%b3%bb%e5%88%97%e4%b9%8b%e4%b8%89%ef%bc%9awindows-%e4%b8%8b-git-%e9%85%8d%e7%bd%ae%e4%b8%8e%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97/</link>
		<comments>http://wangcongming.info/2010/07/git-%e7%b3%bb%e5%88%97%e4%b9%8b%e4%b8%89%ef%bc%9awindows-%e4%b8%8b-git-%e9%85%8d%e7%bd%ae%e4%b8%8e%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 07:35:06 +0000</pubDate>
		<dc:creator>Wang Congming</dc:creator>
				<category><![CDATA[Geek Tweak]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[msysGit]]></category>
		<category><![CDATA[密钥]]></category>

		<guid isPermaLink="false">http://wangcongming.info/?p=237</guid>
		<description><![CDATA[一、安装 默认安装：msysGit 二、配置 1、C:\Program Files\Git\etc\gitconfig 添加： 【注意！】请将第二行最后的 “your-id” 修改成你在服务器上的实际 id，默认是姓名拼音。 [alias] go = "! bash -c \"git pull &#38;&#38; git add .; if [ \\\"$*\\\" == \\\"\\\" ]; then git commit -a; else git commit -am \\\"$*\\\"; fi; git push origin master:your-id;\"" [core] autocrlf = false [gui] encoding = utf-8 [i18n] commitencoding = GB2312 [user] [...]]]></description>
			<content:encoded><![CDATA[<h2 style="margin-top: 30px; font-weight: bold;">一、安装</h2>
<p>默认安装：<a href="http://code.google.com/p/msysgit/downloads/detail?name=Git-1.7.0.2-preview20100309.exe">msysGit</a></p>
<h2 style="margin-top: 40px; font-weight: bold;">二、配置</h2>
<p>1、C:\Program Files\Git\etc\gitconfig 添加：<br />
<strong>【注意！】请将第二行最后的 “your-id” 修改成你在服务器上的实际 id，默认是姓名拼音。</strong></p>
<pre>[alias]
    go = "! bash -c \"git pull &amp;&amp; git add .; if [ \\\"$*\\\" == \\\"\\\" ]; then git commit -a; else git commit -am \\\"$*\\\"; fi; git push origin master:your-id;\""
[core]
    autocrlf = false
[gui]
    encoding = utf-8
[i18n]
    commitencoding = GB2312
[user]
    email = xxx@gmail.com
    name = 某某某</pre>
<p>2、C:\Program Files\Git\etc\inputrc 修改两行为：</p>
<pre>set output-meta on
set convert-meta off</pre>
<p>3、C:\Program Files\Git\etc\git-completion.bash 末尾增加：</p>
<pre>alias ls='ls --show-control-chars --color=auto'</pre>
<p>4、C:\Program Files\Git\etc\profile 末尾增加：</p>
<pre>export LESSCHARSET=utf-8</pre>
<p>【TIP】以上文件最好使用支持 unix 格式的编辑器修改（如 Notepad++、NetBeans），最次也用“写字板”而非“记事本”。</p>
<p>【TIP】若想了解为什么这样设置，请参见：<a href="http://wangcongming.info/2010/07/31/windows-%E4%B8%8B-git-%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E9%80%89%E6%8B%A9%EF%BC%8C%E5%8F%8A-msysgit-%E5%90%84%E7%A7%8D%E4%B8%AD%E6%96%87%E9%97%AE%E9%A2%98%E7%9A%84%E8%A7%A3%E5%86%B3/">Windows 下 Git 客户端的选择，及 msysGit 各种中文问题的解决</a></p>
<h2 style="margin-top: 40px; font-weight: bold;">三、生成密钥</h2>
<p>安装完后，需要生成一对 Key（这里指密钥），然后才能通过加密的方式和服务器的代码库取得同步。</p>
<p>到开始菜单，找到“Git Bash”，运行之，并执行以下命令：</p>
<pre>$ ssh-keygen -t rsa</pre>
<p>程序会提示您输入密钥的文件名，直接按回车即可。<br />
然后会要求你输入一个密码，将来在使用密钥的时候需要提供这个密码。可以输入，也可以不输入直接回车（无论输入还是不输入，都会要求你确认一次）。<br />
确认完毕后，程序将生成一对密钥存放在以下文件夹：</p>
<pre>C:\Users\Administrator[这里替换成你的用户名]\.ssh</pre>
<p>密钥分成两个文件，一个私钥（id_rsa）、一个公钥（id_rsa.pub）。<br />
私钥保存在您的电脑上，公钥交项目负责人添加到服务器上。用户必须拥有与服务器公钥所配对的私钥，才能访问服务器上的代码库。</p>
<p><strong>【注意！】为了项目代码的安全，请妥善保管你的私钥！因为一旦私钥外泄，将可能导致服务器上的代码被泄漏！</strong></p>
<h2 style="margin-top: 40px; font-weight: bold;">四、使用</h2>
<h3>1、克隆代码库</h3>
<p>使用 Windows 资源管理器，打开你打算存放项目代码的文件夹，点右键选择 Git Bash。</p>
<p>在我们的项目管理系统中，每个项目的首页，都有写明代码克隆的地址，比如我们用于测试目的的沙盒项目：</p>
<pre>$ git clone your-name@testing.aysaas.com:/var/projects/sandbox</pre>
<p>在 Git Bash 中运行这条命令就能将沙盒项目中的所有代码（其实只是几个随便测试的文件）克隆到本地。</p>
<p>接着您就可以打开习惯的 IDE（如 NetBeans），投入到项目的开发中啦～！</p>
<p>【TIP】上面命令中的 your-name 要改成你在服务器上实际的用户名。</p>
<h3>2、查看修改差异</h3>
<p>开发过程中，如果你想了解修改了哪些代码，总览所有代码的改动情况，可以在 Git Bash 中输入此命令：</p>
<pre>$ git diff</pre>
<p>【TIP】Git Bash diff 的时候有两个缺点：一、窗口太窄，可能显示不下整行的代码；二、如果代码中有中文，会乱码。如果你碰到这两个问题，可以在项目文件夹下点右键，选择 Git Gui。</p>
<h3>3、提交修改</h3>
<p>每当完成一个阶段的代码，就需要提交代码以记录进展，方便日后查找问题以及团队协作。</p>
<pre>$ git go aaa 修改说明（改动了什么？为什么这样改？）</pre>
<p>【TIP】别忘了 go 后面的 aaa，关于 &#8216;git go&#8217; 命令的详细说明，请参见 <a href="http://wangcongming.info/2010/07/31/windows-%E4%B8%8B-git-%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E9%80%89%E6%8B%A9%EF%BC%8C%E5%8F%8A-msysgit-%E5%90%84%E7%A7%8D%E4%B8%AD%E6%96%87%E9%97%AE%E9%A2%98%E7%9A%84%E8%A7%A3%E5%86%B3/">Windows 下 Git 客户端的选择，及 msysGit 各种中文问题的解决</a></p>
<p><strong>【TIP】请尽量养成勤提交的好习惯。当代码不幸出现问题时，比较容易找出从什么时刻开始出现问题，并回退到该时刻进行调试，最大限度保护已完成的阶段性工作。</strong></p>
<p>【TIP】以上命令，都需要在项目目录下运行。Git Bash 在命令提示符前，会显示当前所在的目录。如果当前不在项目目录之下，需要用 cd 命令切换到项目所在目录。<br />
简单的办法，就是先在资源管理器里打开项目文件夹，再点右键，选择 Git Bash。</p>
<h2 style="margin-top: 40px; font-weight: bold;">五、总结</h2>
<p>至此，从获取代码、查看差异、到提交代码，整个流程都熟悉了。Git 还有比较高级的技巧，大家可以参考 <a href="http://wangcongming.info/2010/07/31/git-%E7%B3%BB%E5%88%97%E4%B9%8B%E5%9B%9B%EF%BC%9Agit-%E8%BF%9B%E9%98%B6%E5%8A%9F%E8%83%BD/">Git 进阶功能</a> 或在线找进一步的资料学习。</p>
]]></content:encoded>
			<wfw:commentRss>http://wangcongming.info/2010/07/git-%e7%b3%bb%e5%88%97%e4%b9%8b%e4%b8%89%ef%bc%9awindows-%e4%b8%8b-git-%e9%85%8d%e7%bd%ae%e4%b8%8e%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Git 系列之二：Windows 下 Git 客户端的选择，及 msysGit 各种中文问题的解决</title>
		<link>http://wangcongming.info/2010/07/windows-%e4%b8%8b-git-%e5%ae%a2%e6%88%b7%e7%ab%af%e7%9a%84%e9%80%89%e6%8b%a9%ef%bc%8c%e5%8f%8a-msysgit-%e5%90%84%e7%a7%8d%e4%b8%ad%e6%96%87%e9%97%ae%e9%a2%98%e7%9a%84%e8%a7%a3%e5%86%b3/</link>
		<comments>http://wangcongming.info/2010/07/windows-%e4%b8%8b-git-%e5%ae%a2%e6%88%b7%e7%ab%af%e7%9a%84%e9%80%89%e6%8b%a9%ef%bc%8c%e5%8f%8a-msysgit-%e5%90%84%e7%a7%8d%e4%b8%ad%e6%96%87%e9%97%ae%e9%a2%98%e7%9a%84%e8%a7%a3%e5%86%b3/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 07:31:07 +0000</pubDate>
		<dc:creator>Wang Congming</dc:creator>
				<category><![CDATA[Geek Tweak]]></category>
		<category><![CDATA[GB2312]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[msysGit]]></category>
		<category><![CDATA[NBGit]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[TortoiseGit]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[中文]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://wangcongming.info/?p=230</guid>
		<description><![CDATA[在 Windows 下用 NetBeans 做 PHP 开发，首先想到的是 NetBeans 的插件：NBGit。 评价：能用；若需没有的功能，可以自定义菜单调用自定义 bat 脚本；开发不活跃，使用没有信心。 第二个则是：TortoiseGit，SVN 小乌龟的 Git 版本。 评价：该有的功能基本都有了，还是不错的。 另外，TortoiseGit 只是 GUI 工具，使用它需要先安装 msysGit，这是正宗的 Git 之 Windows 版本。msysGit 有个简单的 GUI 工具，及简单的 Explorer 集成；但它自带的 Bash 非常好用，深得 Linux 的真传。 选择：msysGit。 理由： NBGit 不用说，功能都不完善，还需要自己定制 bat 脚本（若此，则它同样要依赖 msysGit）；开发不活跃，很可能 NetBeans 下个版本更新就不能用了；况且，我们还有别的项目，不使用 NetBeans。 TortoiseGit 从功能上说是完善的，但它只是功能的堆砌而已，使用时完全体会不到 GUI 带来的便利。相反，它让人感觉很繁琐，一个劲地点鼠标，点来点去全是跟菜单打交道，远离了 Git 命令、远离了 Git 输出提示、远离了真相。 msysGit 的 [...]]]></description>
			<content:encoded><![CDATA[<p>在 Windows 下用 NetBeans 做 PHP 开发，首先想到的是 NetBeans 的插件：NBGit。<br />
评价：能用；若需没有的功能，可以自定义菜单调用自定义 bat 脚本；开发不活跃，使用没有信心。</p>
<p>第二个则是：TortoiseGit，SVN 小乌龟的 Git 版本。<br />
评价：该有的功能基本都有了，还是不错的。</p>
<p>另外，TortoiseGit 只是 GUI 工具，使用它需要先安装 msysGit，这是正宗的 Git 之 Windows 版本。msysGit 有个简单的 GUI 工具，及简单的 Explorer 集成；但它自带的 Bash 非常好用，深得 Linux 的真传。</p>
<p><strong>选择：msysGit。</strong><br />
理由：<br />
NBGit 不用说，功能都不完善，还需要自己定制 bat 脚本（若此，则它同样要依赖 msysGit）；开发不活跃，很可能 NetBeans 下个版本更新就不能用了；况且，我们还有别的项目，不使用 NetBeans。</p>
<p>TortoiseGit 从功能上说是完善的，但它只是功能的堆砌而已，使用时完全体会不到 GUI 带来的便利。相反，它让人感觉很繁琐，一个劲地点鼠标，点来点去全是跟菜单打交道，远离了 Git 命令、远离了 Git 输出提示、远离了真相。</p>
<p>msysGit 的 Bash 非常好用；加上 Git 强大的 alias 功能，我们完全可以自定义一个 $ git go，使得 90% 的情况下只需要这一个命令，即使是不熟悉命令行的 Windows 用户也会觉得很好玩；因为 NBGit、TortoiseGit 都需要 msysGit 做底层，我们直接用底层工具也避免了上层 GUI 带来的额外的 bug。</p>
<p>需要的配置：</p>
<p><strong>1、</strong>C:\Program Files\Git\etc\git-completion.bash：</p>
<pre><strong>alias ls='ls --show-control-chars --color=auto'</strong></pre>
<p>说明：使得在 Git Bash 中输入 ls 命令，可以正常显示中文<strong>文件名</strong>。</p>
<p><strong>2、</strong>C:\Program Files\Git\etc\inputrc：</p>
<pre><strong>set output-meta on
set convert-meta off</strong></pre>
<p>说明：使得在 Git Bash 中可以正常<strong>输入</strong>中文，比如中文的 commit log。</p>
<p><strong>3、</strong>C:\Program Files\Git\etc\profile：</p>
<pre><strong>export LESSCHARSET=utf-8</strong></pre>
<p>说明：$ git log 命令不像其它 vcs 一样，n 条 log 从头滚到底，它会恰当地停在第一页，按 space 键再往后翻页。这是通过将 log 送给 less 处理实现的。以上即是设置 less 的字符编码，使得 $ git log 可以正常显示中文。其实，它的值不一定要设置为 utf-8，比如 latin1 也可以……。还有个办法是 $ git &#8211;no-pager log，在选项里禁止分页，则无需设置上面的选项。</p>
<p><strong>4、</strong>C:\Program Files\Git\etc\gitconfig：<br />
<strong>[alias]<br />
go =</strong> “! bash -c \”git pull &amp;&amp; git add .; if [ \\\"$*\\\" == \\\"\\\" ]; then git commit -a; else git commit -am \\\”$*\\\”; fi; git push origin master:your-id;\”"</p>
<p>说明：强大的 alias，有了这个，我们 90% 的情况下只需要输入 $ git go 这一个命令，免去了先拉后提交再推的繁琐步骤。</p>
<p>两种用法：<br />
$ git go<br />
或<br />
$ git go aaa 修订说明</p>
<p>命令后带修订说明时，会直接提交。需要注意的是，在“修订说明”之前，有还个“aaa”，这是个 bug，参数中的第一个会被忽略，所以随便写一个凑数的……。</p>
<p>若命令行里没有提供修订说明，则会自动弹出一个编辑器，等待输入。默认的编辑器是 Vim。Vim 的使用是很简单的，首先要明白它有两个模式，一个是命令模式、一个是输入模式。Vim 启动的时候默认的是命令模式，需要先按&#8217;i'键，进入输入模式；然后就正常编辑；编辑完成之后，将输入法切换回英文状态，按 Esc 重新进入命令模式；此时按 &#8216;<strong>(Shift):wq</strong>&#8216; 并回车，w 表示写入保存、q 表示退出。完毕！</p>
<p>若实在不习惯 Vim，也可以设置为其它编辑器：</p>
<pre class="terminal">$ git config --global core.editor "notepad"</pre>
<p>其中 notepad 可以替换为更好用的 wordpad、notepad++ 等（不过它们在命令行里无法直接访问，得先设置 PATH 变量）。</p>
<p>以上 alias 是为 Windows 定制的，Linux 下可以写得更优雅，不过鉴于使用上没分别，就保持一致吧～。</p>
<p><strong></strong><strong>[gui]<br />
encoding = utf-8</strong></p>
<p>说明：我们的代码库是统一用的 utf-8，这样设置可以在 git gui 中正常显示代码中的中文。</p>
<p><strong>[i18n]<br />
commitencoding = GB2312</strong></p>
<p>说明：如果没有这一条，虽然我们在本地用 $ git log 看自己的中文修订没问题，但，一、我们的 log 推到服务器后会变成乱码；二、别人在 Linux 下推的中文 log 我们 pull 过来之后看起来也是乱码。这是因为，我们的 commit log 会被先存放在项目的 .git/COMMIT_EDITMSG 文件中；在中文 Windows 里，新建文件用的是 GB2312 的编码；但是 Git 不知道，当成默认的 utf-8 的送出去了，所以就乱码了。有了这条之后，Git 会先将其转换成 utf-8，再发出去，于是就没问题了。</p>
<p><strong>以上，给 Windows 下的同事在 Git Bash 里推代码就比较完美了。不过仍然有 3 个问题：</strong></p>
<p>1、上面的 alias $ git go 有 bug，代码修订说明之前要输入一串字符凑数；</p>
<p>2、$ git diff，如果代码里有中文，会显示乱码；</p>
<p>3、$ git checkout 有时候需要修改/增删很多文件，如果某些文件被占用，会被 Windows 拒绝，导致失败，甚至可能造成版本库出现无法修复的问题。</p>
<p>这 3 个都是可承受的问题，前两个应该有办法解决；第 3 个归功于文件系统，只能尽量避免 checkout，实在需要的时候先注销一次，就不会有问题了。</p>
<p><strong>【TIP】</strong>该文只是解释说明，具体操作请按<a href="http://wangcongming.info/2010/07/31/git-%E7%B3%BB%E5%88%97%E4%B9%8B%E4%B8%89%EF%BC%9Awindows-%E4%B8%8B-git-%E9%85%8D%E7%BD%AE%E4%B8%8E%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/">《Windows 下 git 配置与使用指南》Wiki</a> 执行。</p>
]]></content:encoded>
			<wfw:commentRss>http://wangcongming.info/2010/07/windows-%e4%b8%8b-git-%e5%ae%a2%e6%88%b7%e7%ab%af%e7%9a%84%e9%80%89%e6%8b%a9%ef%bc%8c%e5%8f%8a-msysgit-%e5%90%84%e7%a7%8d%e4%b8%ad%e6%96%87%e9%97%ae%e9%a2%98%e7%9a%84%e8%a7%a3%e5%86%b3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Git 系列之一：版本控制的概念、分布式、Git 简介及其工作流程</title>
		<link>http://wangcongming.info/2010/07/%e7%89%88%e6%9c%ac%e6%8e%a7%e5%88%b6%e7%9a%84%e6%a6%82%e5%bf%b5%e3%80%81%e5%88%86%e5%b8%83%e5%bc%8f%e3%80%81git-%e7%ae%80%e4%bb%8b%e5%8f%8a%e5%85%b6%e5%b7%a5%e4%bd%9c%e6%b5%81%e7%a8%8b/</link>
		<comments>http://wangcongming.info/2010/07/%e7%89%88%e6%9c%ac%e6%8e%a7%e5%88%b6%e7%9a%84%e6%a6%82%e5%bf%b5%e3%80%81%e5%88%86%e5%b8%83%e5%bc%8f%e3%80%81git-%e7%ae%80%e4%bb%8b%e5%8f%8a%e5%85%b6%e5%b7%a5%e4%bd%9c%e6%b5%81%e7%a8%8b/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 07:24:06 +0000</pubDate>
		<dc:creator>Wang Congming</dc:creator>
				<category><![CDATA[Geek Tweak]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://wangcongming.info/?p=207</guid>
		<description><![CDATA[注： Git 的强大、灵活、好用，毋庸置疑。 但也正是 Git 的灵活性，在公司推行时，如何执行统一的流程成为一个问题。我想了不少时间才制订出一个办法。 目的是规范、统一。还有就是，Windows 下的同事，特别是不熟悉命令行的同事，怎样才能使他们好理解，并且觉得简单（之前大家觉得概念太多，难以理解；步骤多，记不住，不小心就搞错，冲突频发）。 说到 Windows，Git 在 Windows 下不如 Linux 下好使，这也是一个需要考虑的问题。 同样是在公司 Wiki 上写的，再次拿到 Blog 来凑数呵呵～。 版本控制 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; 简单地说，就是将在本地开发的代码，定时推送到服务器。每一次修改，记录下它的作者、时间及修改说明等。 相对的，我们也可以从服务器下拉其他人推送的代码，并了解它的作者、时间、修改说明及其具体的修改内容。 这样，版本控制给团队协作开发提供了极大的方便。即使是一个人开发，因为它记录下了我们整个的开发历史，也是极有帮助和价值的。 比如，如果某次修改甚至整个系统出现问题，它也能帮助找回我们珍贵的代码。 分布式版本控制 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; 更进一步，分布式版本控制工具使得我们在本机上即拥有完整的功能，不依赖于服务器，使用更为方便。它们往往也提供其它更好用或更强大的功能，比如灵活的分支管理。 Git &#8212;&#8212;&#8211; Git 是 Linux 之父 Linus Trovalds，为管理 Linux 内核代码而建立的，被认为是分布式版本控制工具中的顶级水准。智能、友好、强健、高效。 Git 工作流程 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- 1、使用中央服务器辅助协作； 2、每人在服务器拥有一个以自己 id 为名称的分支； 3、各人只许推送更新到自己的分支，不允许推送到别人的分支或者 master； 4、master 由专人管理，在合适时 merge 其它分支（开发初期每日自动 merge 各人分支，生产化后则由人工 merge [...]]]></description>
			<content:encoded><![CDATA[<p>注：</p>
<p>Git 的强大、灵活、好用，毋庸置疑。</p>
<p>但也正是 Git 的灵活性，在公司推行时，如何执行统一的流程成为一个问题。我想了不少时间才制订出一个办法。</p>
<p>目的是规范、统一。还有就是，Windows 下的同事，特别是不熟悉命令行的同事，怎样才能使他们好理解，并且觉得简单（之前大家觉得概念太多，难以理解；步骤多，记不住，不小心就搞错，冲突频发）。</p>
<p>说到 Windows，Git 在 Windows 下不如 Linux 下好使，这也是一个需要考虑的问题。</p>
<p>同样是在公司 Wiki 上写的，再次拿到 Blog 来凑数呵呵～。</p>
<h2 style="margin-top: 40px; font-weight: bold;">版本控制</h2>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
简单地说，就是将在本地开发的代码，定时推送到服务器。每一次修改，记录下它的作者、时间及修改说明等。</p>
<p>相对的，我们也可以从服务器下拉其他人推送的代码，并了解它的作者、时间、修改说明及其具体的修改内容。</p>
<p>这样，版本控制给团队协作开发提供了极大的方便。即使是一个人开发，因为它记录下了我们整个的开发历史，也是极有帮助和价值的。</p>
<p>比如，如果某次修改甚至整个系统出现问题，它也能帮助找回我们珍贵的代码。</p>
<h2 style="margin-top: 40px; font-weight: bold;">分布式版本控制</h2>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
更进一步，分布式版本控制工具使得我们在本机上即拥有完整的功能，不依赖于服务器，使用更为方便。它们往往也提供其它更好用或更强大的功能，比如灵活的分支管理。</p>
<h2 style="margin-top: 40px; font-weight: bold;">Git</h2>
<p>&#8212;&#8212;&#8211;<br />
Git 是 Linux 之父 Linus Trovalds，为管理 Linux 内核代码而建立的，被认为是分布式版本控制工具中的顶级水准。智能、友好、强健、高效。</p>
<h2 style="margin-top: 40px; font-weight: bold;">Git 工作流程</h2>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1、使用中央服务器辅助协作；</p>
<p>2、每人在服务器拥有一个以自己 id 为名称的分支；</p>
<p>3、各人只许推送更新到自己的分支，不允许推送到别人的分支或者 master；</p>
<p>4、master 由专人管理，在合适时 merge 其它分支（开发初期每日自动 merge 各人分支，生产化后则由人工 merge 经过 review 的分支）；</p>
<p>5、代码修改 merge 到 master 后，将同步到所有终端。</p>
<p>【TIP】：熟悉之后，你可以创建类似 myId_branchName 的其它分支。</p>
<p>【TIP】：以上只是概念介绍，至于具体的操作，请参考：<a href="http://wangcongming.info/2010/07/31/git-%E7%B3%BB%E5%88%97%E4%B9%8B%E4%B8%89%EF%BC%9Awindows-%E4%B8%8B-git-%E9%85%8D%E7%BD%AE%E4%B8%8E%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/">《Windows 下 Git 配置与使用指南》</a>、 <a href="http://wangcongming.info/2010/07/31/git-%E7%B3%BB%E5%88%97%E4%B9%8B%E5%9B%9B%EF%BC%9Agit-%E8%BF%9B%E9%98%B6%E5%8A%9F%E8%83%BD/">《Git 进阶功能》</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://wangcongming.info/2010/07/%e7%89%88%e6%9c%ac%e6%8e%a7%e5%88%b6%e7%9a%84%e6%a6%82%e5%bf%b5%e3%80%81%e5%88%86%e5%b8%83%e5%bc%8f%e3%80%81git-%e7%ae%80%e4%bb%8b%e5%8f%8a%e5%85%b6%e5%b7%a5%e4%bd%9c%e6%b5%81%e7%a8%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debian Squeeze/sid + Apache + Redmine 0.9.3/trunk + MySQL + git/hg</title>
		<link>http://wangcongming.info/2010/04/debian-squeezesid-apache-redmine-0-9-3trunk-mysql-githg/</link>
		<comments>http://wangcongming.info/2010/04/debian-squeezesid-apache-redmine-0-9-3trunk-mysql-githg/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 04:31:05 +0000</pubDate>
		<dc:creator>Wang Congming</dc:creator>
				<category><![CDATA[Geek Tweak]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Redmine]]></category>
		<category><![CDATA[ror]]></category>

		<guid isPermaLink="false">http://wangcongming.info/?p=186</guid>
		<description><![CDATA[Update: 已可直接从库里安装了～。 # apt-get install redmine redmine-mysql libapache2-mod-passenger _________________________________________________________________________ 按：这是在公司 WIKI 上写的文章，难得这么认真，拿出来分享一下 ：）。对比过十多个项目管理系统，然后在比较好的 Redmine, Trac, Mantis 三个当中选择了 Redmine。文中以 Debian Squeeze 为例，但其它 GNU/Linux 特别是 Debian Lenny / Sid、Ubuntu 应该基本一致。 _________________________________________________________________________ 一、废话 Debian 的库里有最新的 redmine 发布版（0.9.3），一个命令就可以搞定： #apt-get install redmine However……，安装后运行会出现 http 500 service unavailable 等问题。因为 Debian 只有 2.2.3 的 rails，而 redmine 0.9.3 要求 rails 的版本为 2.3.5。 我第一个想法是，既然库里有 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: </strong>已可直接从库里安装了～。</p>
<p># apt-get install redmine redmine-mysql libapache2-mod-passenger<br />
_________________________________________________________________________</p>
<p id="一、废话">按：这是在公司 WIKI 上写的文章，难得这么认真，拿出来分享一下 ：）。对比过十多个项目管理系统，然后在比较好的 Redmine, Trac, Mantis 三个当中选择了 Redmine。文中以 Debian Squeeze 为例，但其它 GNU/Linux 特别是 Debian Lenny / Sid、Ubuntu 应该基本一致。</p>
<p>_________________________________________________________________________</p>
<h3>一、废话</h3>
<p>Debian 的库里有最新的 redmine 发布版（0.9.3），一个命令就可以搞定：</p>
<pre>#apt-get install redmine</pre>
<p>However……，安装后运行会出现 http 500 service unavailable 等问题。因为 Debian 只有  2.2.3 的 rails，而 redmine 0.9.3 要求 rails 的版本为 2.3.5。</p>
<p>我第一个想法是，既然库里有 redmine，就不折腾了，删掉 rails，再手工装一个新版本。可是 redmine 是依赖于 rails  的，要删得一起删。然后我就想，好，保留它，再装一个新版本覆盖之！就是这个想法……，最后遇到了很多问题，又因为对 ror  不熟，在这上面浪费了不少时间。</p>
<p>没办法，全 purge 掉，实实在在从头来吧。以下以 redmine-trunk 版为例（解决了 0.9.3 中存在的 wiki+php  等一些 bug）。</p>
<p>注：以下 # 开头的命令需以 root 身份执行。</p>
<h3 id="二、依赖关系">二、依赖关系</h3>
<pre>#apt-get install ruby rubygems rake mysql-server mysql-client libmysql-ruby libopenssl-ruby
#gem install rails
</pre>
<h3 id="三、下载-redmine">三、下载 redmine</h3>
<pre>/var/projects#svn checkout http://redmine.rubyforge.org/svn/trunk redmine</pre>
<p>注：稳定发行版本下载 <a href="http://rubyforge.org/frs/?group_id=1850">http://rubyforge.org/frs/?group_id=1850</a></p>
<h3 id="四、创建数据库">四、创建数据库</h3>
<pre># mysql -u root -p
mysql&gt; create database redmine character set utf8;
mysql&gt; grant all privileges on redmine.* to redmine@localhost identified by 'PASSWORD';
</pre>
<h3 id="五、数据库配置文件">五、数据库配置文件</h3>
<pre>/var/projects/redmine#cat config/database.yml
production:
  adapter: mysql
  database: redmine
  host: localhost
  username: redmine
  password: PASSWORD
  encoding: utf8
</pre>
<h3 id="六、生成-session-key">六、生成 session key</h3>
<pre>#rake generate_session_store
</pre>
<p>会将结果写入 config/initializers/session_store.rb</p>
<h3 id="七、初始化数据库结构">七、初始化数据库结构</h3>
<pre>#RAILS_ENV=production rake db:migrate
</pre>
<h3 id="八、导入默认设置到数据库">八、导入默认设置到数据库</h3>
<pre>#RAILS_ENV=production rake redmine:load_default_data
</pre>
<h3 id="九、预览！">九、预览！</h3>
<pre>#ruby script/server webrick -e production
</pre>
<p>然后可以用浏览器访问 <a href="http://server:3000/">http://server:3000/</a> ，待测试没问题再继续。</p>
<h3 id="十、用-apache-运行-redmine">十、用 apache 运行 redmine</h3>
<p>WEBrick 虽然能跑，但是超慢！慢到无法忍受的地步（好奇的是，内存和cpu利用率都超低，它在干嘛呢……）。</p>
<p>安装：</p>
<pre>#apt-get install apache2 libapache2-mod-passenger</pre>
<p>权限：</p>
<pre>#chmod -R g+w redmine
#chown -R root:www-data redmine
</pre>
<p>符号链接：</p>
<pre>#ln -s /var/projects/redmine /var/www/redmine
</pre>
<p>配置文件：</p>
<pre>#cat /etc/apache2/conf.d/redmine
RailsEnv production
RailsBaseURI /redmine
</pre>
<p>Done:</p>
<pre>#/etc/init.d/apache reload
$firefox http://server/redmine/
</pre>
<h3 id="十一、安装修改-主题样式（可选）">十一、安装/修改 主题/样式（可选）</h3>
<p>Redmine 支持基本的主题自定义（可以覆盖默认的 css）。</p>
<p>可以到 <a href="http://www.redmine.org/wiki/redmine/Theme_List">http://www.redmine.org/wiki/redmine/Theme_List</a> 下载别人的主题包，解压后将包目录放到 public/themes/ 下面。</p>
<pre>#/etc/init.d/apache reload</pre>
<p>之后，即可访问 <a href="http://server/redmine/settings?tab=display">http://server/redmine/settings?tab=display</a> 选择新的主题。</p>
<p>不过我觉得还是默认的耐看。我直接对默认的主题做了一点修改：</p>
<pre>--- public/stylesheets/application.css    (revision 3628)
+++ public/stylesheets/application.css    (working copy)

+tr.priority-1, table.list.issues tr.priority-1 a { color: black; }
+
+tr.priority-2, table.list.issues tr.priority-2 a { color: #1c1cf3 /*similar to blue*/; }
+tr.priority-3, table.list.issues tr.priority-3 a { color: #1c1cf3; font-weight: bold; }
+
+tr.priority-4, table.list.issues tr.priority-4 a { color: red; }
+tr.priority-5, table.list.issues tr.priority-5 a { color: red; font-weight: bold; }
+
+tr.status-3, table.list.issues tr.status-3 a,
+tr.status-4, table.list.issues tr.status-4 a { color: green; font-weight: normal; }
+
+tr.status-5, table.list.issues tr.status-5 a,
+tr.status-6, table.list.issues tr.status-6 a { color: gray; font-weight: normal; }
</pre>
<p>以上加的几行，使得以不同的颜色区分不同优先级（低/高/紧急等）、不同状态（新建/进行中/反馈/已关闭等）的 issue。</p>
<h3 id="十二、安装插件（可选）">十二、安装插件（可选）</h3>
<p>很方便，下面是安装 email tls 插件的例子：</p>
<pre>#ruby script/plugin install git://github.com/collectiveidea/action_mailer_optional_tls.git</pre>
<p>更新数据库：</p>
<pre>#RAILS_ENV=production rake db:migrate:upgrade_plugin_migrations
#RAILS_ENV=production rake db:migrate_plugins
</pre>
<h3 id="十三、配置-email-发送功能-——-任务建立变更时，发送邮件提醒（可选）">十三、配置 email 发送功能 ——  任务建立/变更时，发送邮件提醒（可选）</h3>
<p>以 GMail 为例，先要安装上一步提到的 email 插件，然后:</p>
<pre>#cat config/email.yml
production:
  delivery_method: :smtp
  smtp_settings:
    tls: true
    address: "smtp.gmail.com"
    port: 587
    domain: "smtp.gmail.com" # 'your.domain.com' for GoogleApps
    authentication: :plain
    user_name: "xxxxx@gmail.com"
    password: "xxxxxxxxxxxxxxxx"
</pre>
<p>完了 reload apache 即可。这里 <a href="http://server/redmine/settings?tab=notifications">http://server/redmine/settings?tab=notifications</a> 有一些设置选项。我去掉了 bcc，选中了纯文本。</p>
<p>修改 1:</p>
<pre>--- app/models/mailer.rb    (revision 3628)
+++ app/models/mailer.rb    (working copy)
-    subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
+    subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.subject}" 

     s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
-    s &lt;&lt; "(#{issue.status.name}) " if journal.new_value_for('status_id')
     s &lt;&lt; issue.subject
</pre>
<p>修改的目的，是使得 redmine 发送的邮件提醒在标题中不要包含 issue  的状态（新建/进行中/已关闭等），从而使得关于同一个问题的所有提醒邮件在 GMail 中都能自动组织成一个会话，非常有利于上下文的理解。</p>
<p>redmine 默认在邮件标题中包含 issue 的状态信息，使得每一次状态变更的邮件都分散到不同的会话中，很讨厌。</p>
<p>修改 2:</p>
<pre>--- config/locales/zh.yml    (revision 3628)
+++ config/locales/zh.yml    (working copy)
-  text_journal_changed: "{{label}} 从 {{old}} 变更为 {{new}}"
-  text_journal_set_to: "{{label}} 被设置为 {{value}}"
-  text_journal_deleted: "{{label}} 已删除 ({{old}})"
-  text_journal_added: "{{label}} {{value}} 已添加"
+  text_journal_changed: "{{label}}：{{old}} -&gt; {{new}}"
+  text_journal_set_to: "{{label}}： -&gt; {{value}}"
+  text_journal_deleted: "已删除：{{label}} ({{old}})"
+  text_journal_added: "已添加：{{label}} {{value}}"
</pre>
<p>对中文翻译的一点修改，这是邮件提醒中对 issue 变更的说明，我觉得太啰嗦了，不直观明了，没有重点。</p>
<p>注：如果你发现发出去的邮件，issue 链接都是带 3000 端口号的，而你现在用 apache 跑 redmine  不需要端口号，可以去 <a href="http://server/redmine/settings">http://server/redmine/settings</a> 改“主机名称”。这是因为你第九步的时候无意中保存过这个设置。</p>
<h3 id="十四、打-patch（可选）">十四、打 patch（可选）</h3>
<p>以下是作者提供的一个 patch，使得在 redmine  中，可以将任务指派给一个组/group，该组的所有成员都会收到邮件提醒（只是，该任务不会显示在“我的工作台”里）。</p>
<pre>redmine#wget http://www.redmine.org/attachments/download/2965/0001-Allow-issues-to-be-assigned-to-a-Group.-2964.patch
redmine#patch -p1 &lt; 0001-Allow-issues-to-be-assigned-to-a-Group.-2964.patch
</pre>
<p>注一：执行 patch 的时候，它会有一点小抱怨，可不予理会。</p>
<p>注二：<a href="http://server/redmine/groups">http://server/redmine/groups</a> ，此处可以增删/编辑小组及其成员。</p>
<h3 id="十五、与版本控制软件集成（githg）">十五、与版本控制软件集成（Git / Mercurial）</h3>
<p>配置系统（使得只有组内的成员才可以查看/修改项目代码，不同的项目使用不同的组）：</p>
<pre>#groupadd saas
#echo 'if [ "saas" == "$(id -gn $(whoami))" ]; then umask 007; fi' &gt;&gt; /etc/profile
</pre>
<p><strong>Update：</strong><br />
在 /etc/profile 中设置 umask 只会影响 login shell，而我们通过 git push 过来的文件仍然是默认的  755 权限（修改 .bashrc 等亦无效）。</p>
<p>要设置 git push 到服务器的文件的权限为 770（同组成员可写），正确的做法是：</p>
<pre># echo "session optional pam_umask.so umask=007" &gt;&gt; /etc/pam.d/common-session</pre>
<p>此外，以下方法应该也可以（没有测试）：</p>
<pre># echo "Subsystem git /bin/bash -c 'umask 007; /usr/bin/git'" &gt;&gt; /etc/ssh/sshd_config</pre>
<p>安装 git：</p>
<pre>#apt-get install git-core</pre>
<p>初始化 git 版本库：</p>
<pre>#mkdir /var/projects/saas
#cd /var/projects/saas
#git --bare init
#chown -R root:saas ../saas
#chmod -R 770 ../saas
</pre>
<p>版本库初始化完成，若要增加新的开发者（各自使用自己的帐号），由管理员执行：</p>
<pre>#useradd -m -s /bin/bash -g saas username # 注意，若不指定，默认的 dash 会出错
</pre>
<p>并将其 pub key 添加到 /home/username/.ssh/authorized_keys 之内。</p>
<p>开发人员在客户端的操作：</p>
<pre>$git config --global user.name "xxx yyy"
$git config --global user.email "xxx@gmai.com"
$git clone username@server:/var/projects/saas
</pre>
<p>测试：</p>
<pre>$cd saas
$echo hello &gt; world
$git add .
$git commit -a -m 'hello world'
$git push origin master
</pre>
<p>以后再 push，就不需要 “origin master” 这两个参数了。</p>
<p>最后，因为初始化版本库的时候我们用了 &#8211;bare 参数，在 /var/projects/saas 下是看不到项目代码文件的。</p>
<p>可以生成一份代码拷贝，用来在 apache 下进行测试：</p>
<pre>#cd /var/www
#git clone /var/projects/saas
#chown -R root:saas saas
#chmod -R 770 saas
#addgroup www-data saas
</pre>
<p>开发者 push 完后，apache 下的代码并不会自动更新，若想测试（这个测试相当于预览，因为开发人员 push  之前是需要先在自己的机器上认真测试的）更新后的代码：</p>
<pre>/var/www/saas$git pull # 注意，各用自己的帐号执行，不要用 root
</pre>
<p>至此，版本管理系统已经正常工作，还剩最后一件事：那就是告诉 Redmine，我们版本库的路径。</p>
<p>浏览器里打开 Redmine，新建一个项目，然后在“设置”里会有个标签叫“版本库”，选择 git，并在 path 里填  /var/projects/saas 就搞定了！</p>
<p>另，hg 的设置与 git 非常相似，大部分参数都一样，不另述。</p>
<h3 id="十六、升级-redmine-svn-trunk（可选）">十六、升级 redmine svn trunk（可选）</h3>
<pre>#svn update
#rake tmp:cache:clear
#rake tmp:sessions:clear
</pre>
<p>可能还要执行第七步和第十二步提到的更新数据库的操作。升级之前应该先备份，在测试实例上确认没有问题再升级。</p>
<h3 id="十七、备份redmine数据">十七、备份redmine数据</h3>
<p>一是数据库：</p>
<pre>#mysqldump -u redmine -p redmine &gt; redmine.$(date +%F).sql</pre>
<p>二是上传的文件：</p>
<pre>/var/projects/redmine#tar cvzf ../redmine.uploaded.files.$(date +%F).tar.gz files/</pre>
<p>（完）</p>
]]></content:encoded>
			<wfw:commentRss>http://wangcongming.info/2010/04/debian-squeezesid-apache-redmine-0-9-3trunk-mysql-githg/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

