﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-xiaomage234-随笔分类-git svn</title><link>http://www.blogjava.net/xiaomage234/category/33941.html</link><description>生命本就是一次凄美的漂流，记忆中放不下的，永远是孩提时代的那一份浪漫与纯真！</description><language>zh-cn</language><lastBuildDate>Fri, 11 Aug 2017 10:34:48 GMT</lastBuildDate><pubDate>Fri, 11 Aug 2017 10:34:48 GMT</pubDate><ttl>60</ttl><item><title>gerrit - first commit</title><link>http://www.blogjava.net/xiaomage234/archive/2017/08/11/432734.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 11 Aug 2017 03:23:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2017/08/11/432734.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/432734.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2017/08/11/432734.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/432734.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/432734.html</trackback:ping><description><![CDATA[<span style="color: #464646; font-family: simsun; background-color: #eaf7fd;">gerrit还是轻易不要尝试引入，它的权限管理，真是复杂极了。对于小型团队，初期这将是个噩梦，但是对于像OpenStack，安卓这种大型team，又是一把利器。</span><div style="color: #464646; font-family: simsun; background-color: #eaf7fd;"></div><div style="color: #464646; font-family: simsun; background-color: #eaf7fd;">下面尝试测试了两个用户的简单情况，很多配置都是系统默认，没有进行啥复杂配置，即使这样也是错误百出，光一个commit就要折腾半天，而且还有些机制没搞清楚。<div></div><div>首先要做的准备工作就是准备两个gerrit用户，user1和user2，并且分别把user1和user2的ssh pub-key通过gerrit setting添加好。</div><div></div><div>1. 首先user1创建一个叫HelloWord的project。</div><div></div><div>&nbsp;<wbr>&nbsp;&nbsp;<wbr>如何创建project请参考前期博客或者官方文档。</div><div></div><div>2. user1在自己的工作环境中把HelloWord clone下来</div><div></div><div>[user1@jenkins ~]$ git clone ssh://user1@gerrit.example.com:29418/HelloWorld.git<br />Initialized empty Git repository in /home/user1/<span style="word-wrap: normal; word-break: normal; line-height: 21px;">HelloWorld</span>/.git/<br />remote: Counting objects: 2, done<br />remote: Finding sources: 100% (2/2)<br />remote: Total 2 (delta 0), reused 0 (delta 0)<br />Receiving objects: 100% (2/2), done.<br />加入user1没有添加ssh pubkey的话，这一步会出permission deny<br /><br />clone后，创建一个README文件并add，commit<br />[user1@jenkins ~]$ cd HelloWorld<br />[user1@jenkins&nbsp;<wbr><span style="word-wrap: normal; word-break: normal; line-height: 21px;">HelloWorld</span>]$ ls<br /><span style="word-wrap: normal; word-break: normal; line-height: 21px;">[user1@jenkins&nbsp;<wbr></span><span style="word-wrap: normal; word-break: normal; line-height: 21px;">HelloWorld</span><span style="word-wrap: normal; word-break: normal; line-height: 21px;">]$&nbsp;<wbr></span>touch README<br />[penxiao@jenkins test]$ git add README&nbsp;<wbr><br />[penxiao@jenkins test]$ git commit -m add README<br />这里注意一点，在下面要push之前，一定要配置好git config的 username和email<br />可以通过命令行或者直接编辑 ~/.gitconfig文件实现，而且email一定要和gerrit里注册的email一致，否者push也会出错。<br />[user1@jenkins HelloWorld]$ git push origin master<br />Counting objects: 3, done.<br />Writing objects: 100% (3/3), 213 bytes, done.<br />Total 3 (delta 0), reused 0 (delta 0)<br />remote: Processing changes: refs: 1, done &nbsp;<wbr>&nbsp;&nbsp;<wbr><br />To ssh://user1@gerrit.example.com:29418/HelloWorld.git<br />&nbsp;<wbr>* [new branch] &nbsp;<wbr>&nbsp;&nbsp;<wbr>&nbsp;&nbsp;<wbr>master -&gt; master<br />[user1@jenkins HelloWorld]$<br /><br />在gerrit的gitweb链接可以查看push的文件。</div><div></div><div>3. user2加入</div><div></div><div><div>[user2@jenkins ~]$ git clone ssh://user1@gerrit.example.com:29418/HelloWorld.git</div><div>Initialized empty Git repository in /home/user2/HelloWorld/.git/</div><div>remote: Counting objects: 3, done</div><div>remote: Finding sources: 100% (3/3)</div><div>remote: Total 3 (delta 0), reused 3 (delta 0)</div><div>Receiving objects: 100% (3/3), done.</div><div>[user2@jenkins ~]$ cd HelloWorld</div><div><div>[user2@jenkins HelloWorld]$ ls</div><div>README</div><div>[user2@jenkins HelloWorld]$&nbsp;<wbr></div></div><div></div><div>user2对README文件进行修改，然后要commit，push</div><div>！！！也同样注意，user2的git config，username和email的配置，email要和gerrit setting里的一致。</div><div></div><div>commit完以后可以看到</div><div></div><div><div>[user2@jenkins HelloWorld]$ git log</div><div>commit 7959fe47bc2d2f53539a1861<wbr>aa6b0d71afe0a531</div><div>Author: user2 &lt;user2@gerrit.com&gt;</div><div>Date: &nbsp;<wbr>&nbsp;Thu Dec 12 00:24:53 2013 -0500</div><div></div><div>&nbsp;<wbr>&nbsp;&nbsp;<wbr>&nbsp;edit README</div><div></div><div>commit 98099fc0de3ba889b18cf36f<wbr>9a5af267b3ddb501</div><div>Author: user1 &lt;user@gerrit.com&gt;</div><div>Date: &nbsp;<wbr>&nbsp;Thu Dec 12 00:15:08 2013 -0500</div><div></div><div>&nbsp;<wbr>&nbsp;&nbsp;<wbr>&nbsp;add README</div><div>[user2@jenkins HelloWorld]$</div></div></div><div></div><div>现在user2要把这次的改变push到gerrit，可以么？</div><div>不行的，可以看到</div><div><div>[user2@jenkins HelloWorld]$ git push origin master</div><div>Counting objects: 5, done.</div><div>Writing objects: 100% (3/3), 249 bytes, done.</div><div>Total 3 (delta 0), reused 0 (delta 0)</div><div>remote: Branch refs/heads/master:</div><div>remote: You are not allowed to perform this operation.</div><div>remote: To push into this reference you need 'Push' rights.</div><div>remote: User: user2</div><div>remote: Please read the documentation and contact an administrator</div><div>remote: if you feel the configuration is incorrect</div><div>remote: Processing changes: refs: 1, done &nbsp;<wbr>&nbsp;&nbsp;<wbr></div><div>To ssh://user2@gerrit.example.com:29418/HelloWorld.git</div><div>&nbsp;<wbr>! [remote rejected] master -&gt; master (prohibited by Gerrit)</div><div>error: failed to push some refs to '<span style="word-wrap: normal; word-break: normal; line-height: 21px;">ssh://user2@gerrit.example.com:29418/HelloWorld.git</span>'</div><div>[user2@jenkins HelloWorld]$&nbsp;<wbr></div><div></div><div>这就是gerrit的精髓所在了。<span style="word-wrap: normal; word-break: normal; line-height: 21px; background-color: #ffffff;">原因是gerrit不允许直接将本地修改同步到远程仓库。客户机必须先push到远程仓库的refs/for/*分支上，等待审核。这也是为什么我们需要使用gerrit的原因。gerrit本身就是个代码审核工具。</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: 21px; background-color: #ffffff;"><br /></span></div><div><div><span style="word-wrap: normal; word-break: normal; line-height: 21px; background-color: #ffffff;">接下来更该push的地址： &nbsp;<wbr></span></div><div><span style="word-wrap: normal; word-break: normal; line-height: 21px; background-color: #ffffff;">[user2@jenkins HelloWorld]$git config remote.origin.push refs/heads/*:refs/for/*&nbsp;&nbsp;<wbr></span></div><div></div><div>此命令实际是更改的是本地仓库test_project/.git/config文件。&nbsp;<wbr></div><div>再次push &nbsp;<wbr>&nbsp;<wbr></div><div><span style="word-wrap: normal; word-break: normal; line-height: 21px; background-color: #ffffff;">[user2@jenkins HelloWorld]$git push origin &nbsp;<wbr></span></div><div>这次不要加master</div><div><div>[user2@jenkins HelloWorld]$ git push origin</div><div>Counting objects: 5, done.</div><div>Writing objects: 100% (3/3), 249 bytes, done.</div><div>Total 3 (delta 0), reused 0 (delta 0)</div><div>remote: Processing changes: refs: 1, done &nbsp;<wbr>&nbsp;&nbsp;<wbr></div><div>remote: ERROR: missing Change-Id in commit message footer</div><div>remote: Suggestion for commit message:</div><div>remote: edit README</div><div>remote:&nbsp;<wbr></div><div>remote: Change-Id: I7959fe47bc2d2f53539a186<wbr>1aa6b0d71afe0a531</div><div>remote:&nbsp;<wbr></div><div>remote: Hint: To automatically insert Change-Id, install the hook:</div><div>remote: &nbsp;<wbr>&nbsp;gitdir=$(git rev-parse --git-dir); scp -p -P 29418 user2@gerrit.example.com:hooks/commit-msg ${gitdir}/hooks/</div><div>remote:&nbsp;<wbr></div><div>remote:&nbsp;<wbr></div><div>To ssh://user2@gerrit.example.com:29418/HelloWorld.git</div><div>&nbsp;<wbr>! [remote rejected] master -&gt; refs/for/master (missing Change-Id in commit message footer)</div><div>error: failed to push some refs to 'ssh://user2@gerrit.example.com:29418/HelloWorld.git'</div></div><div></div><div>尼玛，还是不行，说缺change-Id，为了能让每次commit能自己insert 这个change-id，需要从gerrit server上下载一个脚本</div><div></div><div><span style="word-wrap: normal; word-break: normal; line-height: 21px; background-color: #ffffff;">[user2@jenkins HelloWorld] scp -p 29418 user2@gerrit.example.com:hooks/commit-msg &lt;local path to your git&gt;/.git/hooks/</span></div><div></div><div>然后重新commit</div><div>[user2@jenkins HelloWorld]$ git commit --amend</div><div>再次查看git log</div><div><div>[user2@jenkins HelloWorld]$ git log</div><div>commit f6b5919170875b5b4870fca2<wbr>ab906c516c97006e</div><div>Author: user2 &lt;user2@gerrit.com&gt;</div><div>Date: &nbsp;<wbr>&nbsp;Thu Dec 12 00:24:53 2013 -0500</div><div></div><div>&nbsp;<wbr>&nbsp;&nbsp;<wbr>&nbsp;edit by user2</div><div>&nbsp;<wbr>&nbsp;&nbsp;<wbr>&nbsp;<wbr></div><div>&nbsp;<wbr>&nbsp;&nbsp;<wbr>&nbsp;<strong>Change-Id: Ieac68bebefee7c6d4237fa5<wbr>c058386bf7c4f66b7</strong></div><div></div><div>commit 98099fc0de3ba889b18cf36f<wbr>9a5af267b3ddb501</div><div>Author: user1 &lt;user1@gerrit.com&gt;</div><div>Date: &nbsp;<wbr>&nbsp;Thu Dec 12 00:15:08 2013 -0500</div><div></div><div>&nbsp;<wbr>&nbsp;&nbsp;<wbr>&nbsp;add README</div><div>[user2@jenkins HelloWorld]$&nbsp;<wbr></div></div><div></div><div>这次就有了change id</div><div>然后再次push</div><div><div>[user2@jenkins HelloWorld]$ git push origin</div><div>Counting objects: 5, done.</div><div>Writing objects: 100% (3/3), 289 bytes, done.</div><div>Total 3 (delta 0), reused 0 (delta 0)</div><div>remote: Processing changes: new: 1, refs: 1, done &nbsp;<wbr>&nbsp;&nbsp;<wbr></div><div>remote:&nbsp;<wbr></div><div>remote: New Changes:</div><div>remote: &nbsp;<wbr>&nbsp;http://gerrit.example.com:8080/1</div><div>remote:&nbsp;<wbr></div><div>To ssh://user2@gerrit.example.com:29418/HelloWorld.git</div><div>&nbsp;<wbr>* [new branch] &nbsp;<wbr>&nbsp;&nbsp;<wbr>&nbsp;&nbsp;<wbr>master -&gt; refs/for/master</div><div>[user2@jenkins HelloWorld]$&nbsp;</div></div></div></div></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/432734.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2017-08-11 11:23 <a href="http://www.blogjava.net/xiaomage234/archive/2017/08/11/432734.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>常用 Git 命令清单</title><link>http://www.blogjava.net/xiaomage234/archive/2015/12/25/428825.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 25 Dec 2015 05:32:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/12/25/428825.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/428825.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/12/25/428825.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/428825.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/428825.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 我每天使用 Git ，但是很多命令记不住。一般来说，日常使用只要记住下图6个命令，就可以了。但是熟练使用，恐怕要记住60～100个命令。下面是我整理的常用 Git 命令清单。几个专用名词的译名如下。Workspace：工作区Index / Stage：暂存区Repository：仓库区（或本地仓库）Remote：远程仓库一、新建代码库 # 在当前目录新建一个Git代码库 $ git init  #...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2015/12/25/428825.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/428825.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-12-25 13:32 <a href="http://www.blogjava.net/xiaomage234/archive/2015/12/25/428825.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Git、GitHub、GitLab协作流程详解【转】</title><link>http://www.blogjava.net/xiaomage234/archive/2015/12/25/428819.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 25 Dec 2015 01:52:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/12/25/428819.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/428819.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/12/25/428819.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/428819.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/428819.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 来源：阮一峰的网络日志原文地址：http://www.ruanyifeng.com/blog/2015/12/git-workflow.htmlGit 作为一个源码管理系统，不可避免涉及到多人协作。协作必须有一个规范的流程，让大家有效地合作，使得项目井井有条地发展下去。"协作流程"在英语里，叫做"workflow"或者"flow"，原意是水流，比喻项目像水流那样，顺畅、自然地向前流动，不会发生冲击...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2015/12/25/428819.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/428819.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-12-25 09:52 <a href="http://www.blogjava.net/xiaomage234/archive/2015/12/25/428819.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>git清理空间</title><link>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423866.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 26 Mar 2015 10:32:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423866.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/423866.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423866.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/423866.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/423866.html</trackback:ping><description><![CDATA[<pre src-sh"="" name="code" style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"></pre><pre bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: #657b83; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;">from:<span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px;">http://beta.segmentfault.com/q/1010000002564327</span><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; color: #cb4b16;"></span></code></pre><p style="box-sizing: border-box; margin: 18px 0px; color: #333333; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, STHeiti, sans-serif; line-height: 22.3999996185303px; background-color: #ffffff;">作为 Repo 的维护者，最常见的事情就是从某一 ref 开始到 HEAD保留下来，然后之前的历史删除。因为这个任务比较常见，所以这里也有一个 shell script 分享给你：</p><pre bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: #657b83; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; color: #cb4b16;">#!/bin/bash</span> git checkout --orphan temp <span style="box-sizing: border-box; color: #b58900;">$1</span> git commit -m <span style="box-sizing: border-box; color: #2aa198;">"截取的历史记录起点"</span> git rebase --onto temp <span style="box-sizing: border-box; color: #b58900;">$1</span> master git branch -D temp </code></pre><p style="box-sizing: border-box; margin: 18px 0px; color: #333333; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, STHeiti, sans-serif; line-height: 22.3999996185303px; background-color: #ffffff;">使用的时候这样（比如该脚本保存叫&nbsp;<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">git-detach</code>）：&nbsp;<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">git-detach &lt;ref&gt;</code>，其中&nbsp;<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">&lt;ref&gt;</code>&nbsp;就是你要保留的历史记录的起点。</p><p style="box-sizing: border-box; margin: 18px 0px; color: #333333; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, STHeiti, sans-serif; line-height: 22.3999996185303px; background-color: #ffffff;">需要注意的是，这个脚本只是把历史记录&#8220;分离&#8221;开来，然后其中的一部分没有了可见的引用因此在历史记录里看不见，然而它们的&nbsp;<em style="box-sizing: border-box;">git object</em>&nbsp;仍然存在（换言之你还能恢复过来，自行查阅&nbsp;<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">git-reflog</code>），如果你真要彻底丢掉这些历史（为了给 repo 减肥），可以用&nbsp;<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">git gc --prune</code>，那就再也找不回来了。</p><p style="box-sizing: border-box; margin: 18px 0px; color: #333333; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, STHeiti, sans-serif; line-height: 22.3999996185303px; background-color: #ffffff;">P.S. 这个脚本依赖&nbsp;<em style="box-sizing: border-box;">Orphan Branch</em>，低版本的 Git 不支持（大概是 &lt; v1.7.x），有替代方案自己 Google 吧<br /><br /></p><div><font color="#333333" face="Open Sans, Helvetica Neue, Helvetica, Arial, STHeiti, sans-serif"><span style="line-height: 22.3999996185303px;">$ git filter-branch --tree-filter 'rm -f testme.txt' HEAD</span></font><div>Rewrite bb383961a2d13e12d92be5f5e5d37491a90dee66 (2/2)</div><div>Ref 'refs/heads/master'</div><div>&nbsp;was rewritten</div><div>$ git ls-remote .</div><div>230b8d53e2a6d5669165eed55579b64dccd78d11 &nbsp; &nbsp; &nbsp; &nbsp;HEAD</div><div>230b8d53e2a6d5669165eed55579b64dccd78d11 &nbsp; &nbsp; &nbsp; &nbsp;refs/heads/master</div><div>bb383961a2d13e12d92be5f5e5d37491a90dee66 &nbsp; &nbsp; &nbsp; &nbsp;refs/original/refs/heads/master</div><div>$ git update-ref -d refs/original/refs/heads/master [bb383961a2d13e12d92be5f5e5d37491a90dee66]</div><div>$ git ls-remote .</div><div>230b8d53e2a6d5669165eed55579b64dccd78d11 &nbsp; &nbsp; &nbsp; &nbsp;HEAD</div><div>230b8d53e2a6d5669165eed55579b64dccd78d11 &nbsp; &nbsp; &nbsp; &nbsp;refs/heads/master</div><div>$ rm -rf .git/logs</div><div>$ git reflog --all</div><div>$ git prune</div><div>$ git gc</div><div>$ du -hs</div><div>&nbsp;84K &nbsp; &nbsp;.</div></div><p style="box-sizing: border-box; margin: 18px 0px; background-color: #ffffff;"></p><img src ="http://www.blogjava.net/xiaomage234/aggbug/423866.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-03-26 18:32 <a href="http://www.blogjava.net/xiaomage234/archive/2015/03/26/423866.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Git 使用 - 2. 撤销、远程和打标记</title><link>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423848.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 26 Mar 2015 01:50:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423848.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/423848.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423848.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/423848.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/423848.html</trackback:ping><description><![CDATA[<div>跟踪取消： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git rm --cached x.txt</div><div>&nbsp;</div><div>跟踪取消的含义是，把文件从git中拿出来，不再进行版本跟踪，但保留工作区的文件。操作前，如果：</div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;1）该文件处于已提交状态，则此操作把该文件置成&#8220;未跟踪&#8221;状态，同时，隐性的执行了该文件的需要提交删除操作。再执行 git commit -m "..."， 该文件彻底从 repository 中删除。 &nbsp; &nbsp; &nbsp; 此命令能执行是因为&#8220;已暂存&#8221;与&#8220;已提交&#8221;一致。</div><div>&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;2）该文件处于&#8220;已提交&#8221;状态之后的&#8220;已修改&#8221;。则此操作把该文件置成&#8220;未跟踪&#8221;状态，同时，隐性的执行了该文件的需要提交删除操作。再执行 git commit -m "..."， 该文件彻底从 repository 中删除。而且，已经修改的文件保留，不会丢失。此命令能执行是因为&#8220;已暂存&#8221;与&#8220;已提交&#8221;一致。</div><div>&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;3）该文件处于&#8220;已暂存&#8221;状态之后未修改。则此操作把该文件置成&#8220;未跟踪&#8221;状态，同时，隐性的执行了该文件的需要提交删除操作。再执行 git commit -m "..."， 该文件彻底从 repository 中删除。此命令能执行是因为&#8220;已提交&#8221;与&#8220;已修改&#8221;一致。</div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;4）该文件处于&#8220;已暂存&#8221;状态之后的&#8220;已修改&#8221;。 &nbsp; &nbsp; &nbsp; &nbsp; 此命令不能执行，因为&#8220;已暂存&#8221;既与&#8220;已提交&#8221;不一致，也与&#8220;已修改&#8221;不一致，造成信息丢失的风险，因此，对用户进行风险提示。如果强行删除，则需要加 -f , 即， git rm -f --cached a.txt。 结果是， 把该文件置成&#8220;未跟踪&#8221;状态，同时，隐性的执行了该文件的需要提交删除操作。再执行 git commit -m "..."， 该文件彻底从 repository 中删除。此命令丢失原&#8220;已暂存&#8221;信息。</div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp; &nbsp; &nbsp; 注意：git rm -f --cached a.txt &nbsp;与 git rm -f a.txt 之间的区别： 前者保留工作区的文件，后者是全部删除。</div><div>&nbsp;</div><div>补充提交： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git commit --amend</div><div>说明： 如果上次提交之后没有Stage新的文件，则这次补充提交只更新提交说明。</div><div>&nbsp; &nbsp; &nbsp; &nbsp;如果有重新stage的文件，则这次提交把该文件加入到上次提交，即，本次补充和上次提交合并成一个。</div><div>暂存取消： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git reset HEAD benchmarks.rb</div><div>注意：如果一个文件已经暂存了一个版本，后来又暂存了一个更新的版本，然后用git reset HEAD 取消后暂存的版本，则第一次暂存的本版不会恢复。</div><div>修改取消： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git checkout -- benchmarks.rb</div><div>注意:如果已暂存之后没提交，进行了修改，这个修改取消，使用已暂存来覆盖，而不是已提交的；如果该已暂存已提交，则使用已提交覆盖。也就是说，要想彻底的用已提交的版本覆盖本地修改，则要查看该文件是否有已暂存，如果有，要用上一个命令先把它清除。</div><div>注意：修改取消后，无法恢复。</div><div>总之，只要提交的东西，总能想法设法找回来，但没提交的东西，一旦被覆盖，就有可能永久丢失。</div><div></div><div>[远程操作]</div><div>显示配置了哪些远程服务器： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git remote &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>显示配置了哪些远程服务器，同时显示URL： &nbsp; &nbsp; &nbsp; &nbsp; $ git remote -v &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>显示远程 详细信息： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git remote show origin</div><div>修改远程标识名字： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git remote rename pb paul</div><div>删除远程配置： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git remote rm paul</div><div>增加一个远程配置： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git remote add pb git://github.com/paulboone/ticgit.git&nbsp;</div><div></div><div>获取： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git fetch pb</div><div>或者： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git fetch origin</div><div>注意：</div><div>1）该分支可以用 pb/master 访问</div><div>2）获取到本地之后，并未自动merge，也未改变本地任何东西。</div><div>推送： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git push origin master</div><div>注意，推送的条件：</div><div>1）从该远程克隆；</div><div>2）有写权限；</div><div>3）从上次克隆（或推送）至今没有更新，如果有更新，则你要先 fetch 然后再push。</div><div></div><div>标签操作：</div><div>查看所有标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git tag</div><div>注意：标签显示的顺序无太多含义。</div><div>查看特定标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git tag -l 'v1.4.2.*'</div><div>打新标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git tag -a v1.4 -m 'my version 1.4'</div><div>显示某个标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git show v1.4</div><div>签署标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git tag -s v1.5 -m 'my signed 1.5 tag'</div><div>轻量级标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git tag v1.6</div><div>验证标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git tag -v v1.4.2.1</div><div>后期加注标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git log --pretty=oneline</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git tag -a v1.2 9fceb02</div><div>分享（推送）标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git push origin v1.5</div><div>分享（推送）所有标签： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git push origin --tags</div><img src ="http://www.blogjava.net/xiaomage234/aggbug/423848.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-03-26 09:50 <a href="http://www.blogjava.net/xiaomage234/archive/2015/03/26/423848.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Git 使用 - 1. 文件操作和历史查看 </title><link>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423847.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 26 Mar 2015 01:47:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423847.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/423847.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423847.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/423847.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/423847.html</trackback:ping><description><![CDATA[<div>【简介】&nbsp;</div><div>版本控制系统（VCS, Version Control System） 可以分为集中式（CVCS, Centralized Version Control System, 如 CVS, Subversion）和分布式（DVCS, Distributed Version Control System，如 Git 等）版本控制系统。</div><div>传统的集中式版本控制系统，本地只保存代码库的一个版本拷贝。 所有历史版本都保存在服务器。GIT 与之最大的不同是，本地不仅保存一个快照，而且保存着整个代码库（repository）。因此它可以&#8220;离线&#8221;工作。&nbsp;</div><div>在 Window 上安装： http://code.google.com/p/msysgit</div><div>GIT 起源于 LINUX 开发。Linux 开发早期（1992－2002）没有使用版本控制工具，直到 2002 年开始使用一个非开源的工具 BitKeeper。一开始这个工具还给 Linux 免费使用，后来想收费了，充满自由精神 Linux 成员们肯定不会屈服于这个要挟，一怒之下开发了一个自由的版本控制工具。2005 年，GIT 诞生 。</div><div>&nbsp;</div><div>参考：官网：http://git-scm.com/</div><div>&nbsp; &nbsp; &nbsp;手册：http://www.kernel.org/pub/software/scm/git/docs/</div><div>&nbsp; &nbsp; &nbsp;参考：http://gitref.org/</div><div>&nbsp; &nbsp; &nbsp;ProGit: http://progit.org/book/</div><div>【GIT 基础】</div><div>&nbsp;</div><div>GIT 使用 SHA-1 哈希码（40个字符）来标识提交，同时保证本次提交后整体（一个快照）的完整性。&nbsp;</div><div>文件状态：</div><div>文件状态分为：未跟踪 (untracked) 和已跟踪 (tracked)，已跟踪又分为三种状态： 已暂存（staged），已修改（modified），已提交（committed）</div><div>一般过程如下：</div><div>1） 新建文件，该文件状态为&#8220;未跟踪&#8221;，位于工作区；</div><div>2） 用 git add a.txt &nbsp;加入该文件，状态变为已跟踪的&#8220;已暂存&#8221;，位于暂存区；</div><div>3） 用 git commit a.txt -m "ha" &nbsp;提交该文件，状态变为&#8220;已提交&#8221;，位于代码库（repository ）</div><div>或者，如果存在修改的情况，增加如下2.1和2.2两个步骤：</div><div>&nbsp;</div><div>1） 新建文件，该文件状态为&#8220;未跟踪&#8221;，位于工作区；</div><div>2） 用 git add a.txt &nbsp;加入该文件，状态变为已跟踪的&#8220;已暂存&#8221;，位于暂存区；</div><div>2.1）编辑该文件并保存，状态变为&#8220;已修改&#8221;，位于工作区。（注意，位于暂存区的文件独立存在！）</div><div>2.2） 用 git add a.txt &nbsp;加入该文件，状态变为&#8220;已暂存&#8221;，位于暂存区。（注意，原暂存区的文件被覆盖！）</div><div>3） 用 git commit a.txt -m "ha" &nbsp;提交该文件，状态变为&#8220;已提交&#8221;，位于代码库（repository ）</div><div>考虑更广泛的情况，状态迁移图如下所示：&nbsp;</div><div><img src="http://www.blogjava.net/images/blogjava_net/xiaomage234/git.jpeg" border="0" alt="" /></div><div>Git &lt;wbr&gt;使用 &lt;wbr&gt;- &lt;wbr&gt;1. &lt;wbr&gt;文件操作和历史查看</div><div></div><div>注意：用 git status 查看目前所有文件的状态。</div><div>GIT 配置：</div><div>三种配置范围类型：</div><div>1）所有用户 --system， &nbsp; 存在 /etc/gitconfig 文件中。(对windows来说，是 msysgit 的安装目录)</div><div>2）本用户 --global， &nbsp; &nbsp;存在 ~/.gitconfig &nbsp;文件中。（对windows 来说，是 C:\Documents and Settings\$USER）</div><div>3）本项目 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 存在 .git/config 文件中。</div><div>注意：后面的重载前面的。例如：用--global设置，可以在所有项目中使用这个设置；如果有一个项目你想使用一个特别的设置，就可以使用不带参数的 git config 重新设置，则它只作用于这个项目。如果用 git config --list 查看这些设置，可能会列出多个，但最后那个起作用。</div><div>用户信息</div><div>$ git config --global user.name "John Doe"</div><div>$ git config --global user.email johndoe@example.com</div><div>文本编辑器</div><div>$ git config --global core.editor emacs</div><div>查看配置信息</div><div>$ git config --list</div><div>或者只看一个信息：</div><div>$ git config &lt;key&gt;</div><div>【常用操作】&nbsp;</div><div>（GIT 1.7.4 on &nbsp;Windows)</div><div>获取帮助： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git help &lt;verb&gt;</div><div>初始化仓库： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git init</div><div>（说明： 如果该目录有文件，则都会处于&#8220;未跟踪&#8221;状态的。）</div><div>克隆仓库： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git clone git://github.com/schacon/grit.git</div><div>克隆仓库，并换个名字： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git clone git://github.com/schacon/grit.git mygrit</div><div>跟踪一个新文件： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git add readme.txt</div><div>说明：&nbsp;</div><div>1） 跟踪之后，该文件状态是&#8220;已暂存&#8221;的。 （Changes to be committed:）</div><div>2）修改一个已暂存的文件，该文件会出现在两个记录区中。</div><div>3） 如果跟踪错了，想把他删除（不删除工作区的），则用 git rm --cached readme.txt。状态变成&#8220;未跟踪&#8221;，如果该文件已经修改了，则加 &nbsp;-f 参数强行删除暂存区的文件（已修改的文件不被覆盖）。</div><div>跟踪一组新文件： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git add *.txt</div><div>跟踪一个目录中的所有文件： &nbsp; &nbsp; &nbsp; $ git add mydir</div><div>说明：如果该目录下有子目录，则进行递归操作。</div><div>修改之后，暂存一个文件： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git add readme.txt</div><div>说明：取消已暂存的文件（已暂存到已修改）： &nbsp; &nbsp; &nbsp; &nbsp; $ git reset HEAD readme.txt</div><div></div><div>忽略某些文件： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 在.gitignore 文件中加入下面两行: &nbsp; &nbsp;*.[oa] &nbsp; &nbsp;*~</div><div>*.a &nbsp; &nbsp; &nbsp; # 忽略所有 .a 结尾的文件</div><div>!lib.a &nbsp; &nbsp;# 但 lib.a 除外</div><div>/TODO &nbsp; &nbsp; # 仅仅忽略项目根目录下的 TODO 文件，不包括 subdir/TODO</div><div>build/ &nbsp; &nbsp;# 忽略 build/ 目录下的所有文件</div><div>doc/*.txt # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt</div><div>注意：.gitignore 文件放在工程的根目录即可，但是要把它用 git add 加入跟踪或者提交。</div><div>&nbsp;</div><div>比较：</div><div>查看尚未暂存的更新： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git diff</div><div>说明：比较&#8220;已修改&#8221;和&#8220;已暂存（或已提交）&#8221;。</div><div>查看尚未提交的更新: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git diff --cached</div><div>&nbsp; &nbsp; &nbsp; 或 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git diff --staged</div><div>说明：比较&#8220;已暂存&#8221;和已提交。&nbsp;</div><div>&nbsp;</div><div>提交：</div><div>提交更新（只更新暂存中的）： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git commit</div><div>提交更新（只更新暂存中的）： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git commit -m "task12, added implementation for usr mrg."</div><div>直接提交更新(更新暂存中的和已修改的)： $ git commit -a -m "task12, added implementation forg."</div><div>从文件中取注释： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git commit --file notefile</div><div>&nbsp;</div><div>重新获取：</div><div>抛弃已修改，用已提交覆盖 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git checkout A.java</div><div>说明：此命令对已暂存文件没作用。&nbsp;</div><div>&nbsp;</div><div>删除文件：</div><div>从工作区可以直接删除文件，这是运行 git status， 显示：</div><div>&nbsp;</div><div>&nbsp; Changes not staged for commit:</div><div>&nbsp; (use "git add/rm &lt;file&gt;..." to update what will be committed)</div><div>&nbsp; (use "git checkout -- &lt;file&gt;..." to discard changes in working directory)</div><div>&nbsp; &nbsp; &nbsp; deleted: &nbsp; &nbsp;a</div><div>可以用 git rm 删除 a。注意：如果 a 是已提交的文件，则还需要运行 git commit 以确保在代码库中删除。如果该文件尚未提交，则无需运行git commit。&nbsp;</div><div></div><div>也可以直接使用 git rm 删除文件，但如何文件处于&#8220;已修改&#8221; 则需要加 -f</div><div>移除已跟踪文件，恢复到&#8220;未跟踪&#8221; &nbsp; &nbsp; &nbsp; $ git rm --cached A.java</div><div>说明：如果文件已修改，则需 -f ，并且不覆盖修改过的内容。&nbsp;</div><div>强行移除修改后文件(从暂存区和工作区中删除)： &nbsp; &nbsp; &nbsp;$ git rm -f a.a&nbsp;</div><div>移除目录下的所有文件（递归）： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git rm log/\*.log</div><div>移除目录下的所有文件（无递归）： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git rm log/*.log</div><div>&nbsp;</div><div>改名（只改工作区和暂存区）： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git mv file1 file2</div><div>相当于： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ mv README.txt README</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git rm README.txt</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git add README</div><div>历史查看 ：</div><div>查看提交历史(全部）： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git log</div><div>查看提交历史，并显示统计信息： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git log --stat</div><div>查看提交历史并查看差异： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git log -p</div><div>查看最近2次提交历史并查看差异： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git log -p -2</div><div>查看最近2周内提交历史： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git log --since=2.weeks</div><div>查看某个时刻之后的提交历史： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git log --since="2008-09-14"</div><div>查看某个时刻以前的提交历史： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git log --until="2008-09-14"</div><div>查看某个作者的提交历史： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git log --author="stupid"</div><div>其他：</div><div>-(n) 仅显示最近的 n 条提交</div><div>--since, --after 仅显示指定时间之后的提交。</div><div>--until, --before 仅显示指定时间之前的提交。</div><div>--author 仅显示指定作者相关的提交。</div><div>--committer 仅显示指定提交者相关的提交。</div><div>例如：</div><div>$ git log --pretty="%h:%s" --author=gitster --since="2008-10-01" \</div><div>&nbsp; &nbsp;--before="2008-11-01" --no-merges -- t/</div><div>&nbsp;</div><div>查看提交历史，并单行显示： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git log --pretty=oneline</div><div>查看提交历史，并格式化显示： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git log --pretty=format:"%h - %an, %ar : %s"</div><div>例如：</div><div>$ git log --pretty=format:"%h - %an, %ar : %s"</div><div>ca82a6d - Scott Chacon, 11 months ago : changed the version number</div><div>085bb3b - Scott Chacon, 11 months ago : removed unnecessary test code</div><div>a11bef0 - Scott Chacon, 11 months ago : first commit</div><div>&nbsp;</div><div>%H 提交对象（commit）的完整哈希字串</div><div>%h 提交对象的简短哈希字串</div><div>%T 树对象（tree）的完整哈希字串</div><div>%t 树对象的简短哈希字串</div><div>%P 父对象（parent）的完整哈希字串</div><div>%p 父对象的简短哈希字串</div><div>%an 作者（author）的名字</div><div>� 作者的电子邮件地址</div><div>� 作者修订日期（可以用 -date= 选项定制格式）</div><div>%ar 作者修订日期，按多久以前的方式显示</div><div>%cn 提交者(committer)的名字</div><div>� 提交者的电子邮件地址</div><div>� 提交日期</div><div>%cr 提交日期，按多久以前的方式显示</div><div>%s 提交说明</div><div>&nbsp;</div><div>查看提交历史，并图形化显示： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git log --pretty=format:"%h %s" --graph</div><div>例如：</div><div>$ git log --pretty=format:"%h %s" --graph</div><div>* 2d3acf9 ignore errors from SIGCHLD on trap</div><div>* &nbsp;5e3ee11 Merge branch 'master' of git://github.com/dustin/grit</div><div>|\</div><div>| * 420eac9 Added a method for getting the current branch.</div><div>* | 30e367c timeout code and tests</div><div>* | 5a09431 add timeout protection to grit</div><div>* | e1193f8 support for heads with slashes in them</div><div>|/</div><div>* d6016bc require time for xmlschema</div><div>* &nbsp;11d191e Merge branch 'defunkt' into local</div><div>&nbsp;</div><div>其它：</div><div>-p 按补丁格式显示每个更新之间的差异。</div><div>--stat 显示每次更新的文件修改统计信息。</div><div>--shortstat 只显示 --stat 中最后的行数修改添加移除统计。</div><div>--name-only 仅在提交信息后显示已修改的文件清单。</div><div>--name-status 显示新增、修改、删除的文件清单。</div><div>--abbrev-commit 仅显示 SHA-1 的前几个字符，而非所有的 40 个字符。</div><div>--relative-date 使用较短的相对时间显示（比如，&#8220;2 weeks ago&#8221;）。</div><div>--graph 显示 ASCII 图形表示的分支合并历史。</div><div>--pretty 使用其他格式显示历史提交信息。可用的选项包括 oneline，short，full，fuller 和 format（后跟指定格式）。</div><div>&nbsp;</div><div>最重要的是，如果你觉着上面这些查看历史的命令太难用，你可以使用图形化工具：gitk，一切都清晰了。</div><img src ="http://www.blogjava.net/xiaomage234/aggbug/423847.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-03-26 09:47 <a href="http://www.blogjava.net/xiaomage234/archive/2015/03/26/423847.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Git 使用 - 3. 分支, merge, rebase</title><link>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423846.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 26 Mar 2015 01:26:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423846.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/423846.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/03/26/423846.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/423846.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/423846.html</trackback:ping><description><![CDATA[<div>[基本概念]&nbsp;</div><div></div><div>GIT branch 的本质是一个提交链表的指针。创建一个新的branch，实质是创建了当时提交链表的一个新指针。该指针和原指针独立操作，各自叠加新的提交后，形成各自的分支链。</div><div>&#8220;在分支上&#8221;的含义，新建一个分支之后，建立此分支以前的提交也称为在这个分支上。</div><div>HEAD的含义：当前branch。 随着git branch checkout &lt;branch&gt; 改变。</div><div>分支不是线形性：如果发生过merge，则即使 HEAD 相同，链表也不具有唯一性。（即某些提交有多父情况）</div><div>&nbsp;</div><div>为什么要及时删掉不用的分支：防止提交查看时显示过多的分支。</div><div>merge 时，如果自动merge没有冲突，则 GIT 产生一个新的提交。如果有 冲突，则GIT产生一个未提交。</div><div>实践中，可以有三个分支：</div><div>1， master</div><div>2， dev</div><div>3， Topic：针对某个具体问题，短期存在，需要经常的rebase。</div><div>问题：如果删除一个分支，那么它上面的未 merge 的提交会一起删除吗？</div><div>[基本操作]</div><div>查看分支: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git branch</div><div>创建分支： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git branch mybranch</div><div>切换分支： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git checkout mybranch</div><div>创建并切换分支： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git checkout -b mybranch</div><div>合并分支：(merge from) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git checkout master</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git merge mybranch &nbsp; (merge from mybranch)</div><div>使用 merge工具（有冲突的情况下）： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git mergetool</div><div>删除分支： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git branch -d mybranch</div><div>强制删除分支 (上面有尚未 merge 的提交)： &nbsp; &nbsp; &nbsp; &nbsp;$ git branch -D mybranch</div><div>列出所有分支： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git branch</div><div>查看各个分支最后一次提交： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git branch -v</div><div>查看哪些分支合并入当前分支（可以删了）： &nbsp; &nbsp; &nbsp; &nbsp;$ git branch --merged</div><div>查看哪些分支未合并入当前分支： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git branch --no-merged</div><div></div><div>远程：&nbsp;</div><div>更新远程库到本地： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git fetch origin</div><div>如果有新分支，则分支名：orgin/&lt;branch&gt;</div><div>&nbsp;</div><div>取远程分支合并到本地分支： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git merge origin/mybranch</div><div>用远程分支建一个本地分支： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git checkout -b mybranch origin/mybranch</div><div>推送分支： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git push origin mybranch</div><div>&nbsp;</div><div>推送分支，并换个名字： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git push origin serverfix:awesomebranc</div><div>删除远程分支：　　　　　　　　　　　　　　　　　$ git push origin &nbsp;:mybranch</div><div>&nbsp;</div><div>rebase: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git checkout mybranch</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git rebase master &nbsp; &nbsp;(rebase from master)</div><div>&nbsp;</div><div>举例： &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ git checkout server</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git rebase --onto master server client</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git checkout master</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git merge client &nbsp;(fostforward)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git rebase master server &nbsp;(checkout sever)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git merge server</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git branch -d client</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ git branch -d server</div><div>&nbsp;</div><div>merge 和 rebase 的区别：</div><div>1），从文件结果看，merge 和 rebase 可以达到同样效果。&nbsp;</div><div>2），从历史纪录看，他们存在差异：merge 显示合并后的多父结点，呈现环形， 而 rebase 呈现线性结果，即它对分支历史进行合并操作。rebase 提供更好的历史呈现方式（似分支从未曾发生过），但有风险。 掌握一条原则：Do not rebase commits that you have pushed to a public repository. 即，不要对你提交过的分支进行 rebase。因为本地的改变会造成远端的困惑。&nbsp;</div><div>3）， 在实践中，可以尽量用 merge，慎用 rebase。</div><img src ="http://www.blogjava.net/xiaomage234/aggbug/423846.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-03-26 09:26 <a href="http://www.blogjava.net/xiaomage234/archive/2015/03/26/423846.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>git tag — 标签相关操作</title><link>http://www.blogjava.net/xiaomage234/archive/2015/03/20/423670.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 20 Mar 2015 03:41:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/03/20/423670.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/423670.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/03/20/423670.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/423670.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/423670.html</trackback:ping><description><![CDATA[<div style="border: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; margin: 0px auto; outline: 0px; padding-top: 1.625em; vertical-align: baseline; width: 584.265625px; color: #373737; line-height: 24px; background-color: #ffffff;"><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">标签可以针对某一时间点的版本做标记，常用于版本发布。<br /></p><ul style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em 2.5em; outline: 0px; padding: 0px; vertical-align: baseline; list-style: square;"><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">列出标签</li></ul><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">$ git tag # 在控制台打印出当前仓库的所有标签<br />$ git tag -l &#8216;v0.1.*&#8217; # 搜索符合模式的标签</p><ul style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em 2.5em; outline: 0px; padding: 0px; vertical-align: baseline; list-style: square;"><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">打标签</li></ul><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">git标签分为两种类型：轻量标签和附注标签。轻量标签是指向提交对象的引用，附注标签则是仓库中的一个独立对象。建议使用附注标签。<br /># 创建轻量标签<br />$ git tag v0.1.2-light</p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;"># 创建附注标签<br />$ git tag -a v0.1.2 -m &#8220;0.1.2版本&#8221;</p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">创建轻量标签不需要传递参数，直接指定标签名称即可。<br />创建附注标签时，参数a即annotated的缩写，指定标签类型，后附标签名。参数m指定标签说明，说明信息会保存在标签对象中。</p><ul style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em 2.5em; outline: 0px; padding: 0px; vertical-align: baseline; list-style: square;"><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">切换到标签</li></ul><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">与切换分支命令相同，用<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; line-height: normal;">git checkout [tagname]</code><br />查看标签信息<br />用<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; line-height: normal;">git show</code>命令可以查看标签的版本信息：<br />$ git show v0.1.2</p><ul style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em 2.5em; outline: 0px; padding: 0px; vertical-align: baseline; list-style: square;"><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">删除标签</li></ul><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">误打或需要修改标签时，需要先将标签删除，再打新标签。<br />$ git tag -d v0.1.2 # 删除标签</p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">参数d即delete的缩写，意为删除其后指定的标签。</p><ul style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em 2.5em; outline: 0px; padding: 0px; vertical-align: baseline; list-style: square;"><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">给指定的commit打标签</li></ul><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">打标签不必要在head之上，也可在之前的版本上打，这需要你知道某个提交对象的校验和（通过<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; line-height: normal;">git log</code>获取）。<br /># 补打标签<br />$ git tag -a v0.1.1 9fbc3d0</p><ul style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em 2.5em; outline: 0px; padding: 0px; vertical-align: baseline; list-style: square;"><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">标签发布</li></ul><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">通常的<code style="border: 0px; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; line-height: normal;">git push</code>不会将标签对象提交到git服务器，我们需要进行显式的操作：<br />$ git push origin v0.1.2 # 将v0.1.2标签提交到git服务器<br />$ git push origin &#8211;tags # 将本地所有标签一次性提交到git服务器</p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">&nbsp;</p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">注意：如果想看之前某个标签状态下的文件，可以这样操作</p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">1.git tag &nbsp; 查看当前分支下的标签</p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">2.git &nbsp;checkout v0.21 &nbsp; 此时会指向打v0.21标签时的代码状态，（但现在处于一个空的分支上）</p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">3. cat &nbsp;test.txt &nbsp; 查看某个文件</p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;"><br /></p><p style="margin: 0px 0px 1.625em; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; outline: 0px; vertical-align: baseline;">refer to：http://www.csser.com/dev/580.html</p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/423670.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-03-20 11:41 <a href="http://www.blogjava.net/xiaomage234/archive/2015/03/20/423670.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>从 SVN 迁移到 Git［转］</title><link>http://www.blogjava.net/xiaomage234/archive/2015/03/20/423664.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 20 Mar 2015 02:57:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/03/20/423664.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/423664.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/03/20/423664.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/423664.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/423664.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">转：http://beginor.github.io/2013/03/12/migrate-from-svn-to-git.html</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><div style="color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; line-height: 20px; background-color: #ffffff;"><h3><a name="t0" style="color: rgb(51, 102, 153); width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat;"></a>准备工作</h3><p style="margin-top: 16px; margin-bottom: 16px;">确认所有用户的本地修改都签入到服务器， 将 SVN 源代码的分支尽可能的合并到主干， 已经发布的做好归档信息， 并备份 SVN 库。 虽然迁移到 Git 的风险不大， 但是备份一下总是好的。</p><p style="margin-top: 16px; margin-bottom: 16px;">安装 Git ， 这看起来是废话， 不装 Git 怎么迁移？</p><h3><a name="t1" style="color: rgb(51, 102, 153); width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat;"></a>将用户映射到 Git</h3><p style="margin-top: 16px; margin-bottom: 16px;">创建一个用户映射文件， 将 SVN 用户映射到 Git 用户， 这样可以保留用户的签入历史信息， 比如用户输入的修改记录等， 这个文件看起来是这样子的：</p><pre style="white-space: pre-wrap; word-wrap: break-word; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 9.5px; margin-top: 0px; margin-bottom: 10px; line-height: 1.42857143; word-break: break-all; border: 0px solid #cccccc; background-color: #f5f5f5;"><code nginx"="" style="display: block; padding: 0.5em; color: black; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; overflow-x: auto; background: transparent;"><span style="color: #000088; font-weight: bold;">svnuser1</span> = gituser1 &lt;gituser1<span style="color: #660066;">@yourcompany</span>.com&gt; svnuser2 = gituser2 &lt;gituser2<span style="color: #660066;">@yourcompany</span>.com&gt; </code></pre><p style="margin-top: 16px; margin-bottom: 16px;">这样， 用户 svnuser1 签入的历史信息在迁移之后就会映射成 gituser1 ， svnuser2 映射程 gituser2 。</p><p style="margin-top: 16px; margin-bottom: 16px;">编辑好用户映射文件之后， 保存为 users.txt 。</p><h3><a name="t2" style="color: rgb(51, 102, 153); width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat;"></a>克隆 SVN 库</h3><p style="margin-top: 16px; margin-bottom: 16px;">假设 svn 库的布局是标准的 trunk 、 branches 以及 tags ， 运行下面的命令开始克隆 svn 库：</p><pre style="white-space: pre-wrap; word-wrap: break-word; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 9.5px; margin-top: 0px; margin-bottom: 10px; line-height: 1.42857143; word-break: break-all; border: 0px solid #cccccc; background-color: #f5f5f5;"><code xml"="" style="display: block; padding: 0.5em; color: black; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; overflow-x: auto; background: transparent;">git svn clone <span style="color: #006666;">&lt;<span style="color: #000088; font-weight: bold;">svn</span> <span style="color: #660066;">repo</span> <span style="color: #660066;">url</span>&gt;</span> --no-metadata -A users.txt -t tags -b branches -T trunk <span style="color: #006666;">&lt;<span style="color: #000088; font-weight: bold;">destination</span> <span style="color: #660066;">dir</span> <span style="color: #660066;">name</span>&gt;</span> </code></pre><p style="margin-top: 16px; margin-bottom: 16px;">Git 会克隆 svn 完整的历史记录， 可能会需要很长的时间， 视 svn 库的历史而定。</p><h3><a name="t3" style="color: rgb(51, 102, 153); width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat;"></a>转换分支及归档</h3><p style="margin-top: 16px; margin-bottom: 16px;">克隆完成之后， 所有的 svn 归档在 git 看来都是远程分支 (remote tags) ， 不是真正的 git 归档， 需要将他们手工转换为 git 归档， 然后再删除远程分支， 对于每一个分支或归档， 做如下操作（以 v1.0.1 归档为例）：</p><pre style="white-space: pre-wrap; word-wrap: break-word; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 9.5px; margin-top: 0px; margin-bottom: 10px; line-height: 1.42857143; word-break: break-all; border: 0px solid #cccccc; background-color: #f5f5f5;"><code bash"="" style="display: block; padding: 0.5em; color: black; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; overflow-x: auto; background: transparent;">git tag v1.<span style="color: #008800;">0.1</span> tags/v1.<span style="color: #008800;">0.1</span> git branch -r -d tags/v1.<span style="color: #008800;">0.1</span> </code></pre><p style="margin-top: 16px; margin-bottom: 16px;">所有的归档信息处理完成之后， git 本地库就有了完整的历史记录。</p><h3><a name="t4" style="color: rgb(51, 102, 153); width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat;"></a>提交到 Git 库</h3><p style="margin-top: 16px; margin-bottom: 16px;">现在可以放心的将代码提交到自己的 git 服务器了， 命令如下：</p><pre style="white-space: pre-wrap; word-wrap: break-word; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 9.5px; margin-top: 0px; margin-bottom: 10px; line-height: 1.42857143; word-break: break-all; border: 0px solid #cccccc; background-color: #f5f5f5;"><code perl"="" style="display: block; padding: 0.5em; color: black; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; overflow-x: auto; background: transparent;">git remote add origin git<span style="color: #660066;">@github</span>.com:userid/project.git git <span style="color: #000088; font-weight: bold;">push</span> origin master --tags </code></pre><p style="margin-top: 16px; margin-bottom: 16px;">总的来说， 从 svn 迁移到 git 还是很容易的。</p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/423664.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-03-20 10:57 <a href="http://www.blogjava.net/xiaomage234/archive/2015/03/20/423664.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>git分支管理</title><link>http://www.blogjava.net/xiaomage234/archive/2015/03/20/423665.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 20 Mar 2015 02:57:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/03/20/423665.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/423665.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/03/20/423665.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/423665.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/423665.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #eeeeee;">Git如何进行分支管理？<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1、创建分支<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;创建分支很简单：git branch &lt;分支名&gt;<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2、切换分支<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;git checkout &lt;分支名&gt;<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;该语句和上一个语句可以和起来用一个语句表示：git checkout -b &lt;分支名&gt;<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3、分支合并<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;比如，如果要将开发中的分支（develop），合并到稳定分支（master），<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;首先切换的master分支：git checkout master。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;然后执行合并操作：git merge develop。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果有冲突，会提示你，调用git status查看冲突文件。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解决冲突，然后调用git add或git rm将解决后的文件暂存。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;所有冲突解决后，git commit 提交更改。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4、分支衍合<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分支衍合和分支合并的差别在于，分支衍合不会保留合并的日志，不留痕迹，而 分支合并则会保留合并的日志。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;要将开发中的分支（develop），衍合到稳定分支（master）。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;首先切换的master分支：git checkout master。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;然后执行衍和操作：git rebase develop。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果有冲突，会提示你，调用git status查看冲突文件。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解决冲突，然后调用git add或git rm将解决后的文件暂存。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;所有冲突解决后，git rebase --continue 提交更改。<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5、删除分支<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;执行git branch -d &lt;分支名&gt;<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果该分支没有合并到主分支会报错，可以用以下命令强制删除git branch -D &lt;分支名&gt;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #eeeeee;">http://winuxxan.blog.51cto.com/2779763/508955</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/423665.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-03-20 10:57 <a href="http://www.blogjava.net/xiaomage234/archive/2015/03/20/423665.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CI 系统搭建：二. GitLab 的安装配置</title><link>http://www.blogjava.net/xiaomage234/archive/2015/03/19/423628.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 19 Mar 2015 08:37:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/03/19/423628.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/423628.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/03/19/423628.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/423628.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/423628.html</trackback:ping><description><![CDATA[<h2>from:<span style="font-size: 14px;">http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#i-3</span></h2><p style="margin: 0px 0px 2em; line-height: 22.3999996185303px; color: #666666; font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif; background-color: #ffffff;"><span style="font-size: 12px;">2013-12-26日 | 标签:&nbsp;<a href="http://longgeek.com/tag/ci/" rel="tag" style="color: #666666; text-decoration: none;">CI</a>&nbsp;<a href="http://longgeek.com/tag/git/" rel="tag" style="color: #666666; text-decoration: none;">Git</a>&nbsp;<a href="http://longgeek.com/tag/gitlab/" rel="tag" style="color: #666666; text-decoration: none;">Gitlab</a>&nbsp;| 作者：<a title="" href="http://longgeek.com/" rel="author" style="color: #666666; text-decoration: none;">Geek</a></span></p><div style="color: #333333; font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif; line-height: 22.3999996185303px; background-color: #ffffff;"><h2><a href="http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/" rel="bookmark" title="Permanent Link to CI 系统搭建：二. GitLab 的安装配置" style="color: #336699; text-decoration: none;"></a></h2><div><form name="pdf24Form0" method="post" action="http://doc2pdf.pdf24.org/wordpress.php" target="pdf24PopWin"><a href="http://en.pdf24.org/" target="_blank" title="PDF24 Creator" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/plugins/pdf24-posts-to-pdf/img/sheep_16x16.gif" alt="PDF24 Creator" border="0" width="16" height="16" style="border: medium none; max-width: 580px; height: auto;" /></a>&nbsp;&nbsp;&nbsp;&nbsp;Send article as&nbsp;<a href="http://en.pdf24.org/" target="_blank" style="text-decoration: none; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit;">PDF</a>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="sendEmailTo" value="Enter email address" style="margin: 0px;" />&nbsp;<input type="submit" value="Send" style="margin: 0px;" /></form></div><p style="margin: 0px 0px 1em;">上一篇文章&nbsp;<a href="http://longgeek.com/2013/12/24/ci-build-system-a-basic-environmental-setting-planning/" style="color: #336699; text-decoration: none;">CI 系统搭建：一. 基础环境设置、规划&nbsp;</a>大概规划了下环境，本文主要用来记录安装 Gitlab 的过程，<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-login.jpg" style="color: #336699; text-decoration: none;">主要参考官方文档</a>&nbsp;并没有做太多的修改。</p><p style="margin: 0px 0px 1em;"></p><div id="toc_container"  no_bullets"=""><p style="margin: 0px 0px 1em;">目录</p><ul><li style="list-style-type: square;"><a href="http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#i" style="color: #336699; text-decoration: none;"><span toc_depth_1"="">1</span>&nbsp;设置源</a></li><li style="list-style-type: square;"><a href="http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#i-2" style="color: #336699; text-decoration: none;"><span toc_depth_1"="">2</span>&nbsp;安装依赖包</a></li><li style="list-style-type: square;"><a href="http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#i-3" style="color: #336699; text-decoration: none;"><span toc_depth_1"="">3</span>&nbsp;系统用户</a></li><li style="list-style-type: square;"><a href="http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#GitLab_Shell" style="color: #336699; text-decoration: none;"><span toc_depth_1"="">4</span>&nbsp;GitLab Shell</a></li><li style="list-style-type: square;"><a href="http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#Mysql" style="color: #336699; text-decoration: none;"><span toc_depth_1"="">5</span>&nbsp;Mysql</a></li><li style="list-style-type: square;"><a href="http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#GitLab" style="color: #336699; text-decoration: none;"><span toc_depth_1"="">6</span>&nbsp;GitLab</a></li><li style="list-style-type: square;"><a href="http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#Nginx" style="color: #336699; text-decoration: none;"><span toc_depth_1"="">7</span>&nbsp;Nginx</a></li><li style="list-style-type: square;"><a href="http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#i-4" style="color: #336699; text-decoration: none;"><span toc_depth_1"="">8</span>&nbsp;界面简单使用</a></li></ul></div><h3><span id="i">设置源</span></h3><p style="margin: 0px 0px 1em;"><em>设置国内 163 apt 源</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;"># vim /etc/apt/sources.list deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse deb http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted deb http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted deb http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted deb http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted  deb-src http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse deb-src http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted deb-src http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted deb-src http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted deb-src http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted # apt-get update </code></pre><hr /><h3><span id="i-2">安装依赖包</span></h3><p style="margin: 0px 0px 1em;"><em>Gitlab 依赖包、库</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev \                         libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall \                         libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate </code></pre><p style="margin: 0px 0px 1em;"><em>安装 markdown 文档风格依赖包</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo apt-get install -y python-docutils  </code></pre><p style="margin: 0px 0px 1em;"><em>安装 git，Gerrit 依赖 gitweb，同时 GitLab 依赖 git 版本 &gt;= 1.7.10，Ubuntu apt-get 默认安装的是 1.7.9.5，当然不升级也是没有问题的</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo apt-get install -y git git-core gitweb git-review </code></pre><p style="margin: 0px 0px 1em;"><em>升级 Git 版本（可选）</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo apt-get install -y git gitweb sudo apt-get remove git-core sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential cd /tmp curl --progress https://git-core.googlecode.com/files/git-1.8.4.1.tar.gz | tar xz cd git-1.8.4.1/ make prefix=/usr/local all sudo make prefix=/usr/local install # * 如果升级了 git 的版本，相应修改 Gitlab.yml 中的 git 脚本位置，这一步在 clone gitlab 后在操作* sudo -u git -H vim /home/git/gitlab/config/gitlab.yml bin_path: /usr/local/bin/git </code></pre><p style="margin: 0px 0px 1em;"><em>Gitlab 需要收发邮件，安装邮件服务器</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo apt-get install -y postfix </code></pre><p style="margin: 0px 0px 1em;"><em>如果安装了 ruby1.8，卸载掉，Gitlab 依赖 2.0 以上</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo apt-get remove ruby1.8 </code></pre><p style="margin: 0px 0px 1em;"><em>下载编译 ruby2.0</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">mkdir /tmp/ruby &amp;&amp; cd /tmp/ruby curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz cd ruby-2.0.0-p353 ./configure --disable-install-rdoc make sudo make install </code></pre><p style="margin: 0px 0px 1em;"><em>修改 gem 源指向 taobao</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">gem source -r https://rubygems.org/ gem source -a http://ruby.taobao.org/ </code></pre><p style="margin: 0px 0px 1em;"><em>安装 Bundel 命令</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo gem install bundler --no-ri --no-rdoc </code></pre><hr /><h3><span id="i-3">系统用户</span></h3><p style="margin: 0px 0px 1em;"><em>给 Gitlab 创建一个 git 用户</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo adduser --disabled-login --gecos 'GitLab' git </code></pre><hr /><h3><span id="GitLab_Shell">GitLab Shell</span></h3><p style="margin: 0px 0px 1em;"><em>下载 Gitlab Shell，用来 ssh 访问仓库的管理软件</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git cd gitlab-shell sudo -u git -H cp config.yml.example config.yml </code></pre><p style="margin: 0px 0px 1em;"><em>修改 gitlab-shell/config.yml</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo -u git -H vim /home/git/gitlab-shell/config.yml gitlab_url: "http://gitlab.thstack.com/" </code></pre><p style="margin: 0px 0px 1em;"><em>安装 GitLab Shell</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab-shell sudo -u git -H ./bin/install </code></pre><hr /><h3><span id="Mysql">Mysql</span></h3><p style="margin: 0px 0px 1em;"><em>安装 Mysql 包</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev </code></pre><p style="margin: 0px 0px 1em;"><em>给 Gitlab 创建 Mysql 数据库并授权用户访问</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo mysql -uroot -p &gt; create database gitlabdb; &gt; grant all on gitlabdb.* to 'gitlabuser'@'localhost' identified by 'gitlabpass'; </code></pre><hr /><h3><span id="GitLab">GitLab</span></h3><p style="margin: 0px 0px 1em;"><em>下载 GitLab 源代码，并切换到最新的分支上</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab cd gitlab sudo -u git -H git checkout 6-4-stable </code></pre><p style="margin: 0px 0px 1em;"><em>配置 GitLab，修改 gitlab.yml，其中 host： 项和 gitlab-shell 中 gitlab_url 的主机一致</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml sudo -u git -H vim config/gitlab.yml host: gitlab.thstack.com email_from: gitlab@thstack.com support_mail: gitlab@thstack.com signup_enabled: true             ＃开启用户注册 </code></pre><p style="margin: 0px 0px 1em;"><em>创建相关目录</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab sudo -u git -H mkdir tmp/pids/ sudo -u git -H mkdir tmp/sockets/ sudo -u git -H mkdir public/uploads  sudo -u git -H mkdir /home/git/repositories sudo -u git -H mkdir /home/git/gitlab-satellites </code></pre><p style="margin: 0px 0px 1em;"><em>修改相关目录权限</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo chown -R git:git log/ tmp/ sudo chmod -R u+rwX  log/ tmp/ public/uploads </code></pre><p style="margin: 0px 0px 1em;"><em>修改 unicorn.rb 监听端口为：8081</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab/ sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb sudo -u git -H vim config/unicorn.rb listen "gitlab.thstack.com:8081", :tcp_nopush =&gt; true </code></pre><p style="margin: 0px 0px 1em;"><em>配置 GitLab 访问 mysql 数据库设置</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab/ sudo -u git cp config/database.yml.mysql config/database.yml sudo -u git -H vim config/database.yml   *修改 Production 部分:* production:   adapter: mysql2   encoding: utf8   reconnect: false   database: gitlabdb   pool: 10   username: gitlabuser   password: "gitlabpass"   host: localhost   socket: /var/run/mysqld/mysqld.sock </code></pre><p style="margin: 0px 0px 1em;"><em>设置 GitLab 使用指定邮箱发送邮件，注意 production.rb 的文件格式，开头空两格</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab/ sudo -u git -H vim config/environments/production.rb   #修改 :sendmail 为 :smtp   config.action_mailer.delivery_method = :smtp   config.action_mailer.smtp_settings = {     :address              =&gt; "smtp.googlemail.com",     :port                 =&gt; 587,     :domain               =&gt; 'thstack.com',     :user_name            =&gt; 'gitlab@thstack.com',     :password             =&gt; 'password',     :authentication       =&gt;  :plain,     :enable_starttls_auto =&gt; true   } end          # 上面内容加入到 end 里面 </code></pre><p style="margin: 0px 0px 1em;"><em>安装 gem</em></p><p style="margin: 0px 0px 1em;">修改 Gemfile 文件中源指向为 taobao</p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab/ sudo -u git -H vim Gemfile source "http://ruby.taobao.org/" </code></pre><p style="margin: 0px 0px 1em;">虽然在文件中指向了国内 taobao 源，但是依然会卡一会，耐心等待&#8230;</p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab/ sudo -u git -H bundle install --deployment --without development test postgres aws </code></pre><p style="margin: 0px 0px 1em;"><em>初始化数据库并激活高级功能</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab/ sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production </code></pre><p style="margin: 0px 0px 1em;">输入 yes 来初始化数据库、创建相关表，最后会输出 GitLab Web 管理员用来登录的账号和密码</p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">Do you want to continue (yes/no)? yes ... Administrator account created: login.........admin@local.host password......5iveL!fe </code></pre><p style="margin: 0px 0px 1em;"><em>设置 GitLab 启动服务</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab/ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab sudo update-rc.d gitlab defaults 21 </code></pre><p style="margin: 0px 0px 1em;"><em>设置 GitLab 使用 Logrotate 备份 Log</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab/ sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab </code></pre><p style="margin: 0px 0px 1em;"><em>检查GitLab及其环境的配置是否正确：</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab/ sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production System information System:         Ubuntu 12.04 Current User:   git Using RVM:      no Ruby Version:   2.0.0p353 Gem Version:    2.0.14 Bundler Version:1.3.5 Rake Version:   10.1.0  GitLab information Version:        6.4.2 Revision:       214a013 Directory:      /home/git/gitlab DB Adapter:     mysql2 URL:            http://gitlab.thstack.com HTTP Clone URL: http://gitlab.thstack.com/some-project.git SSH Clone URL:  git@gitlab.thstack.com:some-project.git Using LDAP:     no Using Omniauth: no  GitLab Shell Version:        1.8.0 Repositories:   /home/git/repositories/ Hooks:          /home/git/gitlab-shell/hooks/ Git:            /usr/bin/git </code></pre><p style="margin: 0px 0px 1em;"><em>启动 GitLab 服务</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">/etc/init.d/gitlab restart Shutting down both Unicorn and Sidekiq. GitLab is not running. Starting both the GitLab Unicorn and Sidekiq.. The GitLab Unicorn web server with pid 17771 is running. The GitLab Sidekiq job dispatcher with pid 17778 is running. GitLab and all its components are up and running </code></pre><p style="margin: 0px 0px 1em;"><em>最后编译一下</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production </code></pre><hr /><h3><span id="Nginx">Nginx</span></h3><p style="margin: 0px 0px 1em;"><em>安装 Nginx 包</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">sudo apt-get install -y nginx </code></pre><p style="margin: 0px 0px 1em;"><em>配置 Nginx</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">cd /home/git/gitlab sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab sudo vim /etc/nginx/sites-available/gitlab listen *:80 default_server; server_name gitlab.thstack.com; proxy_pass http://gitlab.thstack.com:8081; </code></pre><p style="margin: 0px 0px 1em;"><em>启动 Nginx</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">/etc/init.d/apache2 stop /etc/init.d/nginx restart </code></pre><p style="margin: 0px 0px 1em;"><em>访问</em></p><pre style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto; padding: 1em; line-height: 1.5em; border: 1px solid #dddddd; margin-top: 1.5em; margin-bottom: 1.5em; background-color: #edf1ff;"><code style="font-family: 'Courier New', Courier, Monaco, 'Lucida Console', monospace; overflow: auto;">用浏览器访问: http://gitlab.thstack.com 用户名：admin@local.host 密码：5iveL!fe </code></pre><p style="margin: 0px 0px 1em;"><a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-login.jpg" style="color: #336699; text-decoration: none;">2</a>: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/insta llation.md</p><h3><span id="i-4">界面简单使用</span></h3><p style="margin: 0px 0px 1em;">使用 admin@local.host 账号登录：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-login.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-login.jpg" alt="gitlab-login" width="1668" height="1350" size-full=""  wp-image-1581"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">登录后系统让修改密码，先修改密码：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-set_pass.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-set_pass.jpg" alt="gitlab-set_pass" width="1600" height="1378" size-full=""  wp-image-1585"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">修改完密码后，用新密码登录一下，然后修改 Admin 用户得邮箱地址为：admin@thstack.com&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-set-email.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-set-email.jpg" alt="gitlab-set-email" width="1698" height="1378" size-full=""  wp-image-1586"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">点击保存更改后，系统会自动给刚才输入的邮箱地址发送一封确认修改信息，点击邮件内容中的连接后会自动用新账号邮箱登录。</p><p style="margin: 0px 0px 1em;">创建一个 GROUP：</p><p style="margin: 0px 0px 1em;"><a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-click-group.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-click-group.jpg" alt="gitlab-click-group" width="1712" height="1418" size-full=""  wp-image-1573"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">输入 Group 名字为：DevGroup&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-create-gourp.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-create-gourp.jpg" alt="gitlab-create-gourp" width="1698" height="1404" size-full=""  wp-image-1577"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">点击创建项目：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-click-project.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-click-project.jpg" alt="gitlab-click-project" width="1672" height="1392" size-full=""  wp-image-1574"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">创建一个项目，名为：OpenStack，这个项目属于 DevGroup:&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-create-project.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-create-project.jpg" alt="gitlab-create-project" width="1662" height="1382" size-full=""  wp-image-1578"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">创建完项目后，点击添加 ssh 密钥：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-click-sshkey.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-click-sshkey.jpg" alt="gitlab-click-sshkey" width="1688" height="1388" size-full=""  wp-image-1575"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">生成 admin@thstack.com 邮箱密钥：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-gen-sshkey.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-gen-sshkey.jpg" alt="gitlab-gen-sshkey" width="1808" height="1382" size-full=""  wp-image-1580"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">在界面输入刚才生成得密钥：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-add-sshkey.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-add-sshkey.jpg" alt="gitlab-add-sshkey" width="1650" height="1380" size-full=""  wp-image-1572"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">再注册一个账号，登录页面点击注册按钮：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-click-user.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-click-user.jpg" alt="gitlab-click-user" width="1706" height="1404" size-full=""  wp-image-1576"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">注册一个 Longgeek 用户，输入邮箱、密码，然后去输入得邮箱验证：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-create-user.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-create-user.jpg" alt="gitlab-create-user" width="1610" height="1338" size-full=""  wp-image-1579"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">创建一个 Longgeek 用户，并生成密钥：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-longgeek-gen-sshkey.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-longgeek-gen-sshkey.jpg" alt="gitlab-longgeek-gen-sshkey" width="3360" height="1948" size-full=""  wp-image-1583"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">用 longgeek@thstack.com 用户登录 GitLab，添加刚才生成得密钥到 sshkey 里：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-longgeek-add-sshkey.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-longgeek-add-sshkey.jpg" alt="gitlab-longgeek-add-sshkey" width="1704" height="1382" size-full=""  wp-image-1582"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">用 admin@thstack.com 用户登录 GitLab，把 longgeek@thstack.com 添加到 DevGroup 组中，权限是 Reporter，这样 longgeek 用户也可以访问 OpenStack 这个项目，不过没有权限直接 Push：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-add-longgeek-gourp.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-add-longgeek-gourp.jpg" alt="gitlab-add-longgeek-gourp" width="1678" height="1412" size-full=""  wp-image-1571"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">用 longgeek@thstack.com 用户登录就可以看到 OpenStack 项目：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-longgeek-view-project.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-longgeek-view-project.jpg" alt="gitlab-longgeek-view-project" width="1664" height="1382" size-full=""  wp-image-1584"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">用 longgeek@thstack.com clone 项目，尝试 push：&nbsp;<a href="http://longgeek.com/wp-content/uploads/2013/12/gitlab-longgeek-try-push1.jpg" style="color: #336699; text-decoration: none;"><img src="http://longgeek.com/wp-content/uploads/2013/12/gitlab-longgeek-try-push1.jpg" alt="gitlab-longgeek-try-push" width="1978" height="1808" size-full=""  wp-image-1588"="" style="border: medium none; max-width: 580px; height: auto;" /></a></p><p style="margin: 0px 0px 1em;">很显然 longgeek 用户是没有 push 到 master 分支得权限。接下来会安装 Gerrit、Jenkins。以及它们三个如何整合成流程。请参考后面得文章。</p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/423628.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-03-19 16:37 <a href="http://www.blogjava.net/xiaomage234/archive/2015/03/19/423628.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用GitLab搭建自己的私有GitHub</title><link>http://www.blogjava.net/xiaomage234/archive/2015/01/14/422225.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 14 Jan 2015 06:44:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/01/14/422225.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/422225.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/01/14/422225.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/422225.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/422225.html</trackback:ping><description><![CDATA[<div fmt"="" style="box-sizing: border-box; line-height: 1.6; word-wrap: break-word; color: #333333; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, STHeiti, sans-serif; background-color: #ffffff;"><p style="box-sizing: border-box; margin: 0px 0px 18px;">Gitlab是一个用Ruby on Rails开发的开源项目管理程序，可以通过WEB界面进行访问公开的或者私人项目。它和Github有类似的功能，能够浏览源代码，管理缺陷和注释。</p><p style="box-sizing: border-box; margin: 18px 0px;">下面介绍如何在 Debian/Ubuntu 和 Centos 下搭建配置 GitLab。</p><h2>安装依赖</h2><p style="box-sizing: border-box; margin: 18px 0px;">Debian/Ubuntu下：</p><pre hljs=""  sql"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;">sudo apt-get <span style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: bold;">install</span> -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-<span style="box-sizing: border-box; font-weight: bold;">server</span> redis-<span style="box-sizing: border-box; font-weight: bold;">server</span> checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate </span></code></pre><p style="box-sizing: border-box; margin: 18px 0px;">安装python(注意需要2.5以上版本)：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> apt-get install -y python python-docutils </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">安装git（注意需要1.7.10以上版本）：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> apt-get install -y git-core </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">Centos下官方仓库的软件比较老旧，推荐<a rel="nofollow" href="http://blog.51yip.com/linux/1337.html" target="_blank" style="box-sizing: border-box; color: #008e59; text-decoration: none; outline: 0px; background: transparent;">先添加epel源</a>，然后再安装依赖：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> yum install git patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel git python python-docutils </code></pre><h2>安装 Ruby 2.0</h2><p style="box-sizing: border-box; margin: 18px 0px;">需要安装Ruby2.0，软件仓库中的Ruby 1.8不支持：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;">mkdir /tmp/ruby &amp;&amp; <span style="box-sizing: border-box; font-weight: bold;">cd</span> /tmp/ruby curl --progress ftp://ftp.ruby-lang.org/pub/ruby/<span style="box-sizing: border-box; color: #008800;">2.0</span>/ruby-<span style="box-sizing: border-box; color: #008800;">2.0</span>.<span style="box-sizing: border-box; color: #008800;">0</span>-p353.tar.gz | tar xz <span style="box-sizing: border-box; font-weight: bold;">cd</span> ruby-<span style="box-sizing: border-box; color: #008800;">2.0</span>.<span style="box-sizing: border-box; color: #008800;">0</span>-p353 ./configure --disable-install-rdoc make <span style="box-sizing: border-box; font-weight: bold;">sudo</span> make install </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">安装Bundler Gem：</p><pre hljs=""  nginx"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> gem install bundler --<span style="box-sizing: border-box; color: #8888ff;">no</span>-ri --<span style="box-sizing: border-box; color: #8888ff;">no</span>-rdoc </code></pre><h2>配置gitlab-shell</h2><p style="box-sizing: border-box; margin: 18px 0px;">创建git用户：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> adduser --system --create-home --comment <span style="box-sizing: border-box; color: #880000;">'GitLab'</span> git   </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">配置gitlab-shell</p><pre hljs=""  perl"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;">su - git -c <span style="box-sizing: border-box; color: #880000;">"git clone https://github.com/gitlabhq/gitlab-shell.git"</span>   su - git -c <span style="box-sizing: border-box; color: #880000;">"cd gitlab-shell &amp;&amp; git checkout v1.3.0"</span>   su - git -c <span style="box-sizing: border-box; color: #880000;">"cp gitlab-shell/config.yml.example gitlab-shell/config.yml"</span>   sed -i <span style="box-sizing: border-box; color: #880000;">"s/localhost/gitlab.51yip.com/g"</span> /home/git/gitlab-shell/config.yml   su - git -c <span style="box-sizing: border-box; color: #880000;">"gitlab-shell/bin/install"</span>   <span style="box-sizing: border-box; font-weight: bold;">chmod</span> <span style="box-sizing: border-box; color: #008800;">600</span> /home/git/.ssh/authorized_keys   <span style="box-sizing: border-box; font-weight: bold;">chmod</span> <span style="box-sizing: border-box; color: #008800;">700</span> /home/git/.ssh </code></pre><h2>数据库</h2><p style="box-sizing: border-box; margin: 18px 0px;">GitLab支持 MySQL 和 PostgreSQL 数据库。下面以 MySQL为例，介绍安装方法：</p><p style="box-sizing: border-box; margin: 18px 0px;">Debian/Ubuntu下使用如下命令安装：</p><pre hljs=""  sql"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;">sudo apt-get <span style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: bold;">install</span> -y mysql-<span style="box-sizing: border-box; font-weight: bold;">server</span> mysql-client libmysqlclient-dev </span></code></pre><p style="box-sizing: border-box; margin: 18px 0px;">Centos下使用如下命令：</p><pre hljs=""  sql"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;">sudo yum <span style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: bold;">install</span> mysql-<span style="box-sizing: border-box; font-weight: bold;">server</span>  sudo chkconfig mysqld <span style="box-sizing: border-box; font-weight: bold;">on</span> </span></code></pre><p style="box-sizing: border-box; margin: 18px 0px;">配置MySQL：</p><pre hljs=""  sql"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;">sudo echo "<span style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: bold;">CREATE</span> <span style="box-sizing: border-box; font-weight: bold;">DATABASE</span> <span style="box-sizing: border-box; font-weight: bold;">IF</span> <span style="box-sizing: border-box; font-weight: bold;">NOT</span> <span style="box-sizing: border-box; font-weight: bold;">EXISTS</span> gitlabhq_production <span style="box-sizing: border-box; font-weight: bold;">DEFAULT</span> <span style="box-sizing: border-box; font-weight: bold;">CHARACTER</span> <span style="box-sizing: border-box; font-weight: bold;">SET</span> <span style="box-sizing: border-box; color: #880000;">'utf8'</span> <span style="box-sizing: border-box; font-weight: bold;">COLLATE</span> <span style="box-sizing: border-box; color: #880000;">'utf8_unicode_ci'</span>;</span>" | mysql -u root  sudo echo "<span style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: bold;">UPDATE</span> mysql.<span style="box-sizing: border-box; font-weight: bold;">user</span> <span style="box-sizing: border-box; font-weight: bold;">SET</span> <span style="box-sizing: border-box; font-weight: bold;">Password</span>=<span style="box-sizing: border-box; font-weight: bold;">PASSWORD</span>(<span style="box-sizing: border-box; color: #880000;">'123456'</span>) <span style="box-sizing: border-box; font-weight: bold;">WHERE</span> <span style="box-sizing: border-box; font-weight: bold;">User</span>=<span style="box-sizing: border-box; color: #880000;">'root'</span>;</span> <span style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: bold;">FLUSH</span> <span style="box-sizing: border-box; font-weight: bold;">PRIVILEGES</span>;</span>" | mysql -u root  </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">注意，用你的密码替换<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">123456</code>。</p><p style="box-sizing: border-box; margin: 18px 0px;">安装配置 gitlab</p><pre hljs=""  nginx"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">su</span> - git -c <span style="box-sizing: border-box; color: #880000;">"git clone https://github.com/gitlabhq/gitlabhq.git gitlab"</span>   su - git -c <span style="box-sizing: border-box; color: #880000;">"cd gitlab;git checkout 5-1-stable"</span>   su git -c <span style="box-sizing: border-box; color: #880000;">"cp config/gitlab.yml.example config/gitlab.yml"</span>   su git -c <span style="box-sizing: border-box; color: #880000;">"mkdir /home/git/gitlab-satellites"</span>   su git -c <span style="box-sizing: border-box; color: #880000;">"mkdir public/uploads"</span>   su git -c <span style="box-sizing: border-box; color: #880000;">"mkdir -p tmp/sockets/"</span>   su git -c <span style="box-sizing: border-box; color: #880000;">"mkdir -p tmp/pids/"</span>   sed -i <span style="box-sizing: border-box; color: #880000;">"s/ host: localhost/ host: gitlab.segmentfault.com/g"</span> config/gitlab.yml   sed -i <span style="box-sizing: border-box; color: #880000;">"s/from: gitlab<span style="box-sizing: border-box;">@localhost</span>/from: gitlab<span style="box-sizing: border-box;">@gitlab</span>.segmentfault.com/g"</span> config/gitlab.yml   su git -c <span style="box-sizing: border-box; color: #880000;">"cp config/puma.rb.example config/puma.rb"</span>   su git -c <span style="box-sizing: border-box; color: #880000;">'git config --global user.name "GitLab"'</span>   su git -c <span style="box-sizing: border-box; color: #880000;">'git config --global user.email "gitlab<span style="box-sizing: border-box;">@gitlab</span>.segmentfault.com"'</span> </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">注意将<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">gitlab.segmentfault.com</code>替换为你自己的内容。</p><p style="box-sizing: border-box; margin: 18px 0px;">配置数据库连接：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> su git -c <span style="box-sizing: border-box; color: #880000;">"cp config/database.yml.mysql config/database.yml"</span> <span style="box-sizing: border-box; font-weight: bold;">sudo</span> sed -i <span style="box-sizing: border-box; color: #880000;">"s/secure password/mysql的root密码/g"</span> config/database.yml </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">安装MySQL需要的Gems</p><pre hljs=""  sql"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;">sudo -u git -H bundle <span style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: bold;">install</span> <span style="box-sizing: border-box; color: #888888;">--deployment --without development test postgres aws</span> </span></code></pre><p style="box-sizing: border-box; margin: 18px 0px;">初始化：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> -u git -H bundle <span style="box-sizing: border-box; font-weight: bold;">exec</span> rake gitlab:setup RAILS_ENV=production <span style="box-sizing: border-box; font-weight: bold;">sudo</span> cp lib/support/init.d/gitlab /etc/init.d/gitlab <span style="box-sizing: border-box; font-weight: bold;">sudo</span> chmod +x /etc/init.d/gitlab <span style="box-sizing: border-box; font-weight: bold;">sudo</span> update-rc.d gitlab defaults <span style="box-sizing: border-box; color: #008800;">21</span> </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">查看是否配置妥当：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> -u git -H bundle <span style="box-sizing: border-box; font-weight: bold;">exec</span> rake gitlab:env:info RAILS_ENV=production </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">重启GitLab：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> service gitlab start </code></pre><h2>配置Nginx</h2><p style="box-sizing: border-box; margin: 18px 0px;">Debian/Ubuntu下：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> apt-get install -y nginx </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">CentOS下：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> yum install nginx </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">下载配置文件样例：</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab <span style="box-sizing: border-box; font-weight: bold;">sudo</span> ln <span style="box-sizing: border-box;">-s</span> /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">修改&nbsp;<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">/etc/nginx/sites-available/gitlab</code>，特别留意将&nbsp;<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">YOUR_SERVER_FQDN</code>&nbsp;改成自己的。</p><p style="box-sizing: border-box; margin: 18px 0px;">重启nginx:</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; color: black; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;"><span style="box-sizing: border-box; font-weight: bold;">sudo</span> service nginx restart </code></pre><p style="box-sizing: border-box; margin: 18px 0px;">好了，你可以登录GitLab了，默认安装后的用户名：<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">admin@local.host</code>，密码<code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">5iveL!fe</code>。</p></div><div style="box-sizing: border-box; color: #333333; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, STHeiti, sans-serif; background-color: #ffffff;"><ul pull-left"="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10.5px; float: left !important; list-style: none; padding: 0px; font-size: 0px;"><li style="box-sizing: border-box; padding: 0px; font-size: 13px; display: inline-block; margin-right: 5px;"><a href="http://segmentfault.com/t/github/blogs" data-toggle="popover" data-img="http://sfault-avatar.b0.upaiyun.com/154/051/1540511964-1040000000091226_huge100" data-placement="top" data-original-title="github" data-id="1040000000091226" style="box-sizing: border-box; color: #017e66; text-decoration: none; outline: 0px; display: inline-block; padding: 0px 8px; height: 24px; line-height: 24px; text-align: center; border-radius: 2px; background: #e7f2ed;">github</a></li>&nbsp;<li style="box-sizing: border-box; padding: 0px; font-size: 13px; display: inline-block; margin-right: 0px;"><a href="http://segmentfault.com/t/gitlab/blogs" data-toggle="popover" data-img="" data-placement="top" data-original-title="gitlab" data-id="1040000000154452" style="box-sizing: border-box; color: #ffffff; text-decoration: none; outline: 0px; display: inline-block; padding: 0px 8px; height: 24px; line-height: 24px; text-align: center; border-radius: 2px; background: #017e66;">gitla</a></li></ul></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/422225.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-01-14 14:44 <a href="http://www.blogjava.net/xiaomage234/archive/2015/01/14/422225.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我的 Git 偏好設定</title><link>http://www.blogjava.net/xiaomage234/archive/2014/12/24/421773.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 24 Dec 2014 07:07:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2014/12/24/421773.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/421773.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2014/12/24/421773.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/421773.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/421773.html</trackback:ping><description><![CDATA[<p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">1. 讓 Command Line 指令列顯示目前處在哪一個 Git Branch 分支，最早是在&nbsp;<a href="http://rgba.tumblr.com/post/520663635/including-current-git-branch-in-your-bash-prompt" style="box-sizing: border-box; color: #bc360a; text-decoration: none;">RGBA</a>&nbsp;看到這一招，非常方便。另外我最近看到一個點子是顯示從上一次 commit 之後過了多久時間，這可以提醒你是不是該 commit 了 XD</p><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">請修改家目錄的 ~/.bash_profile 檔案 (我是用 Bash)。</p><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;"></p><div id="gist897951" style="box-sizing: border-box; color: #333333; font-size: 16px; font-family: 'Source Sans Pro', Helvetica, sans-serif; line-height: 24px; background-color: #ffffff;"><div style="box-sizing: border-box; margin-bottom: 1em; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; border-width: 1px; border-style: solid; border-color: #dddddd #dddddd #cccccc; border-radius: 3px;"><div gist-syntax"="" style="box-sizing: border-box; overflow: auto; word-wrap: normal; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #dddddd;"><div style="box-sizing: border-box; font-size: 12px; line-height: 1.4;"><table cellpadding="0" cellspacing="0"  highlight"="" style="box-sizing: border-box; border-bottom-style: solid; border-bottom-color: #ededed; border-collapse: collapse; border-spacing: 0px; font-size: 12px; line-height: 1.4; margin: 0px; width: 965px; padding: 0px; color: #333333; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><tbody style="box-sizing: border-box;"><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; text-align: right; border-top-style: solid; border-top-color: #ededed; padding: 0.5em; color: #aaaaaa; border-right-style: solid; border-right-color: #eeeeee; line-height: 1.4;"><span id="file-gistfile1-txt-L1" rel="file-gistfile1-txt-L1" style="box-sizing: border-box; display: block; clear: right;">1</span><span id="file-gistfile1-txt-L2" rel="file-gistfile1-txt-L2" style="box-sizing: border-box; display: block; clear: right;">2</span><span id="file-gistfile1-txt-L3" rel="file-gistfile1-txt-L3" style="box-sizing: border-box; display: block; clear: right;">3</span><span id="file-gistfile1-txt-L4" rel="file-gistfile1-txt-L4" style="box-sizing: border-box; display: block; clear: right;">4</span><span id="file-gistfile1-txt-L5" rel="file-gistfile1-txt-L5" style="box-sizing: border-box; display: block; clear: right;">5</span><span id="file-gistfile1-txt-L6" rel="file-gistfile1-txt-L6" style="box-sizing: border-box; display: block; clear: right;">6</span><span id="file-gistfile1-txt-L7" rel="file-gistfile1-txt-L7" style="box-sizing: border-box; display: block; clear: right;">7</span><span id="file-gistfile1-txt-L8" rel="file-gistfile1-txt-L8" style="box-sizing: border-box; display: block; clear: right;">8</span><span id="file-gistfile1-txt-L9" rel="file-gistfile1-txt-L9" style="box-sizing: border-box; display: block; clear: right;">9</span><span id="file-gistfile1-txt-L10" rel="file-gistfile1-txt-L10" style="box-sizing: border-box; display: block; clear: right;">10</span><span id="file-gistfile1-txt-L11" rel="file-gistfile1-txt-L11" style="box-sizing: border-box; display: block; clear: right;">11</span><span id="file-gistfile1-txt-L12" rel="file-gistfile1-txt-L12" style="box-sizing: border-box; display: block; clear: right;">12</span><span id="file-gistfile1-txt-L13" rel="file-gistfile1-txt-L13" style="box-sizing: border-box; display: block; clear: right;">13</span><span id="file-gistfile1-txt-L14" rel="file-gistfile1-txt-L14" style="box-sizing: border-box; display: block; clear: right;">14</span><span id="file-gistfile1-txt-L15" rel="file-gistfile1-txt-L15" style="box-sizing: border-box; display: block; clear: right;">15</span><span id="file-gistfile1-txt-L16" rel="file-gistfile1-txt-L16" style="box-sizing: border-box; display: block; clear: right;">16</span><span id="file-gistfile1-txt-L17" rel="file-gistfile1-txt-L17" style="box-sizing: border-box; display: block; clear: right;">17</span></td><td style="box-sizing: border-box; border-top-style: solid; border-top-color: #ededed; padding: 0.5em !important;"><pre style="box-sizing: border-box; color: #666666; overflow: auto; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; margin-top: 0px !important; margin-bottom: 0px !important; padding: 0px !important; line-height: inherit !important; border: 0px !important; background: transparent !important;"><div id="file-gistfile1-txt-LC1" style="box-sizing: border-box;">function git_branch { </div><div id="file-gistfile1-txt-LC2" style="box-sizing: border-box;">    ref=$(git symbolic-ref HEAD 2&gt; /dev/null) || return; </div><div id="file-gistfile1-txt-LC3" style="box-sizing: border-box;">    echo "("${ref#refs/heads/}") "; </div><div id="file-gistfile1-txt-LC4" style="box-sizing: border-box;">} </div><div id="file-gistfile1-txt-LC5" style="box-sizing: border-box;">&nbsp; </div><div id="file-gistfile1-txt-LC6" style="box-sizing: border-box;">function git_since_last_commit { </div><div id="file-gistfile1-txt-LC7" style="box-sizing: border-box;">    now=`date +%s`; </div><div id="file-gistfile1-txt-LC8" style="box-sizing: border-box;">    last_commit=$(git log --pretty=format:%at -1 2&gt; /dev/null) || return; </div><div id="file-gistfile1-txt-LC9" style="box-sizing: border-box;">    seconds_since_last_commit=$((now-last_commit)); </div><div id="file-gistfile1-txt-LC10" style="box-sizing: border-box;">    minutes_since_last_commit=$((seconds_since_last_commit/60)); </div><div id="file-gistfile1-txt-LC11" style="box-sizing: border-box;">    hours_since_last_commit=$((minutes_since_last_commit/60)); </div><div id="file-gistfile1-txt-LC12" style="box-sizing: border-box;">    minutes_since_last_commit=$((minutes_since_last_commit%60)); </div><div id="file-gistfile1-txt-LC13" style="box-sizing: border-box;">     </div><div id="file-gistfile1-txt-LC14" style="box-sizing: border-box;">    echo "${hours_since_last_commit}h${minutes_since_last_commit}m "; </div><div id="file-gistfile1-txt-LC15" style="box-sizing: border-box;">} </div><div id="file-gistfile1-txt-LC16" style="box-sizing: border-box;">&nbsp; </div><div id="file-gistfile1-txt-LC17" style="box-sizing: border-box;">PS1="[\[\033[1;32m\]\w\[\033[0m\]] \[\033[0m\]\[\033[1;36m\]\$(git_branch)\[\033[0;33m\]\$(git_since_last_commit)\[\033[0m\]$ "  </div></pre></td></tr></tbody></table></div></div><div style="box-sizing: border-box; padding: 10px; overflow: hidden; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica, arial, freesans, clean, sans-serif; color: #999999; background-color: #f7f7f7;"><a href="https://gist.github.com/ihower/897951/raw/gistfile1.txt" style="box-sizing: border-box; color: #666666; text-decoration: none; font-weight: bold; float: right;">view raw</a><a href="https://gist.github.com/ihower/897951#file-gistfile1-txt" style="box-sizing: border-box; color: #666666; text-decoration: none; font-weight: bold;">gistfile1.txt</a>&nbsp;hosted with ❤ by&nbsp;<a href="https://github.com/" style="box-sizing: border-box; color: #666666; text-decoration: none; font-weight: bold;">GitHub</a></div></div></div><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;"></p><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;"></p><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">結果如下，各位可以看到目前處在 master 分支，並且<a href="https://github.com/ihower/jobs.ruby.tw" style="box-sizing: border-box; color: #bc360a; text-decoration: none;">這個專案</a>已經過了 1821 個小時沒有 commit 了&#8230;. :p</p><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;"><a href="http://ihower.tw/blog/wp-content/uploads/2011/04/git-bash.png" style="box-sizing: border-box; color: #bc360a; text-decoration: none;"><img src="http://ihower.tw/blog/wp-content/uploads/2011/04/git-bash.png" alt="" title="git-bash" width="617" height="359" size-full=""  wp-image-5480"="" style="box-sizing: border-box; border: 0px; vertical-align: middle; max-width: 100%; height: auto; margin: 5px 0px;" /></a></p><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">2. 安裝 Git 的 Bash autocompletion，這樣按 tab 就會有自動完成的效果，它甚至包括 git checkout 時都可以抓到你的 branch 名稱。這裡我用&nbsp;<a href="http://ihower.tw/blog/archives/4308" style="box-sizing: border-box; color: #bc360a; text-decoration: none;">Homebrew</a>&nbsp;來安裝 bash-completion，這套件其實包括很多 autocompletion script，你可以去 /usr/local/etc/bash_completion.d 這個目錄找找看。</p><pre style="box-sizing: border-box; color: #666666; margin-top: 20px; margin-bottom: 20px; overflow: auto; padding: 20px; white-space: pre-wrap; word-wrap: break-word; background: #f5f5f5;">brew install bash-completion cp /usr/local/etc/bash_completion.d/git-completion.bash ~/.git-bash-completion.sh </pre><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">編輯 ~/.bash_profile 加入</p><pre style="box-sizing: border-box; color: #666666; margin-top: 20px; margin-bottom: 20px; overflow: auto; padding: 20px; white-space: pre-wrap; word-wrap: break-word; background: #f5f5f5;">[ -f ~/.git-bash-completion.sh ] &amp;&amp; . ~/.git-bash-completion.sh </pre><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">3. 打開 Git 的 color 顏色設定，這樣 Git 指令的輸出結果才會加上顏色，像是 git status 等：</p><pre style="box-sizing: border-box; color: #666666; margin-top: 20px; margin-bottom: 20px; overflow: auto; padding: 20px; white-space: pre-wrap; word-wrap: break-word; background: #f5f5f5;">git config --global color.ui true </pre><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">4. 設定你偏好的文字編輯器和 diff 工具</p><pre style="box-sizing: border-box; color: #666666; margin-top: 20px; margin-bottom: 20px; overflow: auto; padding: 20px; white-space: pre-wrap; word-wrap: break-word; background: #f5f5f5;">git config --global core.editor git config --global merge.tool opendiff </pre><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">5. 最後，我個人喜歡以下的 alias：</p><pre style="box-sizing: border-box; color: #666666; margin-top: 20px; margin-bottom: 20px; overflow: auto; padding: 20px; white-space: pre-wrap; word-wrap: break-word; background: #f5f5f5;">git config --global alias.co checkout git config --global alias.ci commit git config --global alias.st status git config --global alias.br branch </pre><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">這樣只要輸入 git st 就是 git status 了。</p><p style="box-sizing: border-box; margin: 0px 0px 24px; color: #141412; font-family: 'Source Sans Pro', Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">FYI，以上 git 設定檔的位置在 ~/.gitconfig，你也可以直接修改這個檔案。</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/421773.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2014-12-24 15:07 <a href="http://www.blogjava.net/xiaomage234/archive/2014/12/24/421773.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CentOS 6.5下Git服务器搭建</title><link>http://www.blogjava.net/xiaomage234/archive/2014/12/19/421560.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 19 Dec 2014 02:40:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2014/12/19/421560.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/421560.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2014/12/19/421560.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/421560.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/421560.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 时间:2014-04-14 11:49来源:blog.51cto.com&nbsp;作者:&#8220;游响云停&#8221; 博客&nbsp;举报&nbsp;点击:6031次1 关于版本控制版本控制是一种记录一个或若干文件内容变化，以便将来查阅特定版本修订情况的系统。有以下三种版本控制系统：1. 本地版本控制系统许多人习惯用复制整个项目目录的方式来保存不同的版本，或许还会改名加上备份时间以示区别...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2014/12/19/421560.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/421560.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2014-12-19 10:40 <a href="http://www.blogjava.net/xiaomage234/archive/2014/12/19/421560.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>git在windows上配置ssh公钥</title><link>http://www.blogjava.net/xiaomage234/archive/2014/12/19/421559.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 19 Dec 2014 02:39:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2014/12/19/421559.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/421559.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2014/12/19/421559.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/421559.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/421559.html</trackback:ping><description><![CDATA[<dl style="border-width: 0px; padding: 15px 0px 0px; margin: 0px; list-style: none; float: left; width: 670px; height: 35px; text-align: center; font-size: 21px; font-weight: bold; font-family: 宋体; line-height: normal; background-color: #ffffff;"><dd style="border-width: 0px; padding: 0px; margin: 0px; list-style: none;"><br /></dd></dl><dl style="border-width: 0px; padding: 10px 20px; margin: 0px; list-style: none; float: left; width: 630px; font-size: 12px; color: #999999; font-family: 宋体; line-height: normal; background-color: #ffffff;"><dd line_blue"="" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none; height: 30px; overflow: hidden; float: left; width: 500px; background: url(http://www.2cto.com/statics/images/xxbule.jpg) 0% 22px repeat-x;">2013-05-18 10:02:31 &nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.2cto.com/os/201305/211731.html#comment_iframe" style="color: #1f3a87; text-decoration: none; font-weight: bold; padding: 5px 0px 5px 20px; background: url(http://www.2cto.com/statics/images/icon/user_comment.png) 0% 50% no-repeat;">我来说两句&nbsp;</a>&nbsp;&nbsp; &nbsp;&nbsp; 作者：沉睡一千年</dd><dd line_blue"="" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none; height: 30px; overflow: hidden; float: left; width: 130px; text-align: right; background: url(http://www.2cto.com/statics/images/xxbule.jpg) 0% 22px repeat-x;"><span id="favorite"><a style="color: #1f3a87;">收藏</a>&nbsp;</span>&nbsp;&nbsp;&nbsp;<a target="_blank" href="http://www.2cto.com/index.php?m=member&amp;c=content&amp;a=publish&amp;modid=1&amp;siteid=1" style="color: #1f3a87; text-decoration: none;"><img border="0" src="http://www.2cto.com.c1.open.360cdn.cn/statics/images/dl.jpg" data-am-src="http://www.2cto.com/statics/images/dl.jpg" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none;"  alt="" />我要投稿</a></dd></dl><dl id="fontzoom" style="border-width: 0px; padding: 0px 20px 20px; margin: 0px; list-style: none; float: left; width: 630px; color: #333333; line-height: 28px; font-family: 宋体; background-color: #ffffff;"><dd id="Article" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none;"><div style="border-width: 0px; margin: 0px; list-style: none;">git在windows上配置ssh公钥</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none;">一 .设置git的user name和email：</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none;">$ git config --global user.name "lxyz"</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none;">$ git config --global user.email "1129103472@qq.com"</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none;">二 生成密钥</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none;">ssh-keygen -t rsa -C &#8220;1129103472@qq.com&#8221;</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;按3个回车，密码为空。(不要输密码)</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none;">然后到.ssh下面将id_rsa.pub里的内容复制出来粘贴到github个人中心的账户设置的ssh key里面</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none;">git for windows<a href="http://www.2cto.com/soft" target="_blank" style="color: #333333; text-decoration: none;">下载</a>地址：</div><div style="border-width: 0px; margin: 0px; list-style: none;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none;">http://code.google.com/p/msysgit/downloads/list</div></dd></dl><img src ="http://www.blogjava.net/xiaomage234/aggbug/421559.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2014-12-19 10:39 <a href="http://www.blogjava.net/xiaomage234/archive/2014/12/19/421559.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>svn 过滤目录</title><link>http://www.blogjava.net/xiaomage234/archive/2011/11/15/363800.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Tue, 15 Nov 2011 03:22:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2011/11/15/363800.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/363800.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2011/11/15/363800.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/363800.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/363800.html</trackback:ping><description><![CDATA[<div>svn propedit svn:ignore 【dir name】</div><img src ="http://www.blogjava.net/xiaomage234/aggbug/363800.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2011-11-15 11:22 <a href="http://www.blogjava.net/xiaomage234/archive/2011/11/15/363800.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>svn: Unrecognized URL scheme[已经解决，问题分析] [转]</title><link>http://www.blogjava.net/xiaomage234/archive/2009/04/17/266130.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 17 Apr 2009 04:59:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2009/04/17/266130.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/266130.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2009/04/17/266130.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/266130.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/266130.html</trackback:ping><description><![CDATA[<h2>from : http://bbs.iusesvn.com/thread-801-1-1.html</h2>
<h2>svn: Unrecognized URL scheme[已经解决，问题分析]</h2>
<div class="t_msgfont" id="postmessage_4329">我在执行 SVN CO HTTP：// 的时候，出现了<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=svn">svn</span>: Unrecognized URL scheme的错误：（ <br />
<br />
<strong>首先，大家可以在SVN 官方的FAQ的翻译中找到如下问题说明</strong><br />
<br />
Subversion 使用外掛系統來存取檔案庫. 目前有三個這樣的外掛: ra_local 可以存取本地檔案庫, ra_<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=dav">dav</span> 可以透過 WebDAV 存取檔案庫, 而 ra_svn 可以透過 <span class="t_tag" onclick="tagshow(event)" href="tag.php?name=svnserve">svnserve</span> 伺服器來進行本地或遠端的存取. 當你想要在 Subversion 進行一個作業時, 用戶端會試著依 URL schema 動態載入一個外掛. file:// URL 會試著載入 ra_local, 而 http:// URL 會試著輸入 ra_dav, 以此類推. <br />
<br />
你看到的這個錯誤, 表示動態連結器/載入器無法找到要載入的外掛. 這個發生的原因, 通常是因為你以共享程式庫的方式編譯 Subversion, 但是還沒有執行 make install 就要執行它. 另一個可能就是你執行了 make install, 但是程式庫把它存在動態連結器/載入器不認得的地方. 在 Linux 下, 你可以把那個程式庫目錄加進 /etc/ld.so.<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=conf">conf</span>, 然後執行 ldconfig, 讓連結器/載入器可以找到程式庫. 如果你不想這麼作, 或是你沒有 root 存取權限, 你可以在 LD_LIBRARY_PATH 環境變數指定該程式庫目錄.<br />
<br />
<strong>其次，我们可以执行一下SVN，看看ra_dav 是否加载</strong><br />
<br />
svn，版本 1.4.0 (r21228)<br />
<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E7%BC%96%E8%AF%91">编译</span>于 Jan&nbsp;&nbsp;5 2007，16:31:46<br />
<br />
Copyright (C) 2000-2006 CollabNet.<br />
Subversion is open source software, see <a href="http://subversion.tigris.org/" target="_blank">http://<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=subversion">subversion</span>.tigris.org/</a><br />
This product includes software developed by CollabNet (<a href="http://www.collab.net/)." target="_blank">http://www.Collab.Net/).</a><br />
<br />
可使用以下的档案库存取 (RA) <span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E6%A8%A1%E5%9D%97">模块</span>：<br />
<br />
* ra_svn : 使用svn<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E7%BD%91%E7%BB%9C">网络</span>协议<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E8%AE%BF%E9%97%AE">访问</span>档案库的模块。<br />
&nbsp;&nbsp;- handles 'svn' scheme<br />
* ra_local : 访问本地磁盘的档案库模块。<br />
<br />
发现我确实没有加载ra_dav 这个模块，不过按照上面的<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E6%8F%90%E7%A4%BA">提示</span><span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E8%A7%A3%E5%86%B3">解决</span>办法，我已经在 /etc/ld.so.conf 中增界了 /<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=usr">usr</span>/local/svn/lib 这个<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E7%9B%AE%E5%BD%95">目录</span>，并且重新陨星了 ldconfg 但似乎这样还是加载不进去，，<br />
<br />
<strong>接着，我们发现那个模块并没有加载，经过查看configure 的过程，我们发现我们需要安装一个NEON的<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E6%8F%92%E4%BB%B6">插件</span></strong><br />
<br />
一定要<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E4%B8%8B%E8%BD%BD">下载</span> 0.25.5 的，最新版本的不能用<br />
<br />
然后把下载下来的东西，COPY 去 SVN的安装目录，这里记住一定要把NEON 的目录名字，从 neon.1.25.5 改成 neon 不然SVN还是不会认的。。<br />
<br />
NEON 下载<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%E5%9C%B0%E5%9D%80">地址</span>： <a href="http://www.webdav.org/neon/" target="_blank">http://www.<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=web">web</span>dav.org/neon/</a><br />
<br />
<strong>最后，发现问题解决</strong><br />
<br />
svn, version 1.4.2 (r22196)<br />
&nbsp; &nbsp;compiled Jan 11 2007, 12:10:11<br />
<br />
Copyright (C) 2000-2006 CollabNet.<br />
Subversion is open source software, see <a href="http://subversion.tigris.org/" target="_blank">http://subversion.tigris.org/</a><br />
This product includes software developed by CollabNet (<a href="http://www.collab.net/)." target="_blank">http://www.Collab.Net/).</a><br />
<br />
The following repository access (RA) <span class="t_tag" onclick="tagshow(event)" href="tag.php?name=mod">mod</span>ules are available:<br />
<br />
* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.<br />
&nbsp;&nbsp;- handles 'http' scheme<br />
* ra_svn : Module for accessing a repository using the svn network protocol.<br />
&nbsp;&nbsp;- handles 'svn' scheme<br />
* ra_local : Module for accessing a repository on local disk.<br />
&nbsp;&nbsp;- handles 'file' scheme<br />
<br />
<br />
希望大家碰见问题，解决以后多多交流，：-）</div>
<img src ="http://www.blogjava.net/xiaomage234/aggbug/266130.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2009-04-17 12:59 <a href="http://www.blogjava.net/xiaomage234/archive/2009/04/17/266130.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>subversion分支介绍</title><link>http://www.blogjava.net/xiaomage234/archive/2009/03/04/257740.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 04 Mar 2009 03:38:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2009/03/04/257740.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/257740.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2009/03/04/257740.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/257740.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/257740.html</trackback:ping><description><![CDATA[分支,标签,与合并几乎是所有版本控制系统的基本概念.如果你不熟悉这些功能,我们在这章提供了一个很好<br />
的介绍.如果你非常熟悉了,也能很好的让你看看Subversion是如何实现这些功能的.<br />
分支是版本控制的一项基本的功能.如果你将要使用Subversion来管理你的数据.这是一个特色你将最终依赖<br />
它.这章要求你已经对Subversion的基本概念比较熟悉.<br />
<br />
什么是分支?<br />
假设你需要在你的电脑上维护一份被分离的文档,一个手册或是别的什么.某天要求你对同份文档做一个不同<br />
的修改分离,但分离后他们两者只有一小部分不同,因此只有轻微的不同.<br />
你将怎么解决这种处境?显而易见的方法是不是:可以再拷贝这份文档,然后保存两个不同的分离版本.当某个<br />
部分要进行修改时,只要写入对应的文件就可以了.<br />
经常需要对两个拷贝版本进行同样的修改.例如:如果发现一个打印错误在第一个文件里,这也很可能存在第二<br />
个拷贝文件里.这两个文件是相同的的.<br />
这就是分支的基本概念,一条基于另外一条开发线存在的分支.并共享在分离之前的日志.一个分支就象一个拷<br />
贝的存在,并从那里离开,并具有自己的历史.<br />
图:Figur 4.1. Branches of development<br />
Subversion提供了一些功能来保持文件或目录分支的平行性.允许通过拷贝数据来创建分支,并记录与源文件<br />
的关系.也能帮助你将一个分支的修改复制到另外其他的支流上.总的来说,能够映射出不同的工作拷贝.这样<br />
就可以在不同的分支上进行工作.<br />
<br />
使用分支<br />
图:Figure 4.2. Starting repository layout<br />
假设Sally与你同时拥有"calc"项目的工作副本,并都有/calc/trunk的工作副本.所有项目相关的文件都<br />
在/calc目录下,因为你们的团队已经商定/calc/trunk用于存放开发主线.<br />
此时你被要求完成一个任务就是新增项目的一个基本新特性.这将需要很长的时间来完成,并可能回影响到项<br />
目中的大部分晚间.问题是你不想与Sally有任何冲突,她正在修改项目中的一些存在的小BUG.并依赖于最新发<br />
布的项目版本,这里(/calc/trunk)主线版本是最有效的.如果你提交修改那么肯定会打乱Sally的修改工作.<br />
一种策略就是进入一个空洞:你和Sally在一到两周内停止共享信息.那就是开始获取整顿在你工作副本的所有<br />
文件,并不做任何提交一直到你完成工作任务.这个方案存在着很多问题,第一,这样一来做不安全.很多人喜欢<br />
频繁的将工作结果上传到版本库,已防止工作副本被突发事件破坏引起的后果.第二,不够容易.如果你在不同<br />
的机器上工作,你就需要手工的将工作副本进行拷贝修改.最后,当你完成你的所有修改后,你将发现很难将你<br />
的工作合并到主线项目的代码中去.<br />
更好的解决方法就是创,建所有你自己的分支.能频繁的提交工作在不与其他人的冲突下.也能有选择性的共享<br />
信息.<br />
<br />
创建一个分支<br />
创建一个分支非常简单-只需要用svn copy命令拷贝项目就可以.Subversion不单支持单文件,也支持整个文件<br />
目录的分支创建.在此例中,我们要拷贝/calc/trunk文件夹.那么应该把拷贝放在那里呢?任何地方你想要放置<br />
的地方.这里需要提到项目的策略在库中有/calc/branches目录空间,并你想要拷贝的目录名重命名为my-<br />
calc-branch.<br />
有两种不同的方法来进行拷贝.首先介绍有些麻烦的方法.只是为了让概念清晰一点.首先,检出版本库./calc.<br />
使用svn copy命令拷贝要进行分支的文件目录.<br />
$ cd bigwc<br />
$ svn copy trunk branches/my-calc-branch<br />
$ svn status<br />
A&nbsp; +&nbsp;&nbsp; branches/my-calc-branch<br />
在这个例自立,拷贝命令递归拷贝trunk下的文件到新的工作目录.branches/my-calc-branch.你可以从svn <br />
status 命令,心得目录被添加版本库中.同时注意"+"符号前面的字母A.他表明添加的列表是一些数据的拷贝,<br />
并不是新添加的版本库的数据.当年提交修改后,版本库就会创建/calc/branches/my-calc-branch在版本库中<br />
通过拷贝/calc/trunk,而不是通过工作副本将数据传送到版本库.<br />
$ svn commit -m "Creating a private branch of /calc/trunk."<br />
Adding&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; branches/my-calc-branch<br />
Committed revision 341.<br />
现在介绍一种简单的创建分支的方法,那就是可以通过给svn copy 命令传入两个URL路径来实现.<br />
$ svn copy http://svn.example.com/repos/calc/trunk \<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http://svn.example.com/repos/calc/branches/my-calc-branch \<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -m "Creating a private branch of /calc/trunk."<br />
Committed revision 341.<br />
从版本库的角度来看,实际上这两种方法并无任何区别.注意区别只在与本地客户端,后者可以立即执行分支任<br />
务,简单,并不需要你检出庞大的工作副本.这种方法是最常用的.<br />
图 4.3. Repository with new copy<br />
<br />
廉价的拷贝<br />
Subversion的库经过特别的设计.当你拷贝一个文件目录是,你不需要担心会占用大量的版本库容量-实际上版<br />
本库并不会真正的拷贝数据.取而代之的是建立一个新的目录路口来指向已存在的目录树.如果你是UNIX的用<br />
户,这与磁盘连接的概念是相同的.后面对文件或是目录的修改也是影响被拷贝文件目录.任何能够使用该概念<br />
的地方Subversion都会利用该理念.<br />
这也是为什么听到廉价拷贝这个词.我们不需要担心文件目录有多大-拷贝的花费都是非常微小的.这种特性也<br />
是每次提交所做的事,每个版本都是一次廉价拷贝.除了很少的一点修改数据进行保存.<br />
当然,这些机制或数据共享对于用户都是隐藏不可见的.我们能简单的看到拷贝目录.主要点就是拷贝是非常廉<br />
价的,无论是时间还是空间.如果你用这种方法拷贝是非常快的.当然可以随心所欲的进行分支.<br />
<br />
使用分支进行工作<br />
现在我们建立了项目的一个份支,我们就可以检出该分支并开始工作使用它.<br />
$ svn checkout http://svn.example.com/repos/calc/branches/my-calc-branch<br />
A&nbsp; my-calc-branch/Makefile<br />
A&nbsp; my-calc-branch/integer.c<br />
A&nbsp; my-calc-branch/button.c<br />
Checked out revision 341.<br />
这个工作副本并无任何特别之处;只是简单镜像了一个库中项目.当你提交修改后,Sally并不期望当她更新工<br />
作副本的时候看到这些修改.因为她的工作副本是/calc/trunk.<br />
让我们假设看看一个星期里所发生的事<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; You make a change to /calc/branches/my-calc-branch/button.c, which creates revision 342.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; You make a change to /calc/branches/my-calc-branch/integer.c, which creates revision 343.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sally makes a change to /calc/trunk/integer.c, which creates revision 344.<br />
现在这里有两条独立的开发线<br />
图Figure 4.4. The branching of one file's history<br />
<br />
分支背后的关键概念<br />
这里有两点重要的内容需要在这里记住.第一,Subversion并没有冲突分支的概念-它只知道怎么去进行拷贝.<br />
当你拷贝一个目录是,结果就是目录是一个独立的分支.你可能回想像一个不同的目录被建立或被处理.但对于<br />
Subversion只是平常的目录控制区别只是再扩展一个历史日志信息.第二,因为这种拷贝机制,Subversion的分<br />
支只是平常的存储在版本库中,而不像其他的版本控制系统,分支是真正存储了目录文件.<br />
注意,Subversion并不支持不同版本库之间拷贝也使用映射机制,所以他只能在同版本库下工作.
<img src ="http://www.blogjava.net/xiaomage234/aggbug/257740.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2009-03-04 11:38 <a href="http://www.blogjava.net/xiaomage234/archive/2009/03/04/257740.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>svn如何换一个用户登录</title><link>http://www.blogjava.net/xiaomage234/archive/2008/08/21/223400.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 21 Aug 2008 02:25:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2008/08/21/223400.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/223400.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2008/08/21/223400.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/223400.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/223400.html</trackback:ping><description><![CDATA[因为第一次登录并保存密码之后，会缓存到本地，所以要删除这么一个缓存文件。<br />
地址是：&nbsp;%APPDATA%\Subversion\auth\svn.simple 
<img src ="http://www.blogjava.net/xiaomage234/aggbug/223400.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2008-08-21 10:25 <a href="http://www.blogjava.net/xiaomage234/archive/2008/08/21/223400.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>