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

<channel>
	<title>易博云天 &#187; Git</title>
	<atom:link href="http://www.eavea.com/blog/index.php/tag/git/feed" rel="self" type="application/rss+xml" />
	<link>http://www.eavea.com/blog</link>
	<description>专注技术：学习、交流、分享、免费，每天进步一点点！</description>
	<lastBuildDate>Mon, 13 Mar 2023 07:04:16 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6.1</generator>
		<item>
		<title>Git迁移仓库并保留commit记录</title>
		<link>http://www.eavea.com/blog/index.php/gitqianyicangkubingbaoliucommitjilu.html</link>
		<comments>http://www.eavea.com/blog/index.php/gitqianyicangkubingbaoliucommitjilu.html#comments</comments>
		<pubDate>Tue, 14 Apr 2020 06:57:59 +0000</pubDate>
		<dc:creator>eavea</dc:creator>
				<category><![CDATA[技术周边]]></category>
		<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://www.eavea.com/blog/?p=36</guid>
		<description><![CDATA[Git迁移仓库并保留commit记录 在支持 Git 的代码托管平台间进行仓库的迁移，并保留历史 commit [&#8230;]]]></description>
				<content:encoded><![CDATA[<div>Git迁移仓库并保留commit记录</div>
<blockquote><p>在支持 Git 的代码托管平台间进行仓库的迁移，并保留历史 commit 记录。</p></blockquote>
<h2 id="toc-heading-1">一、作用</h2>
<p>把在 A 托管平台的仓库完全的迁移到 B 托管平台，保留 commit 历史记录。</p>
<h2 id="toc-heading-2">二、场景</h2>
<p>将 Gitlab 上的仓库迁移到 GitHub<br />
将 Coding 上的仓库迁移到 GitHub<br />
将 Gitee 上的仓库迁移到 GitHub<br />
……<br />
迁移前后，保留 commit 历史记录，即在迁移后的新仓库中能查询历史提交信息，同时也能保留小绿点。</p>
<h2 id="toc-heading-3">三、步骤</h2>
<ul>
<li>建立新仓库</li>
<li>克隆旧仓库</li>
<li>推送新仓库</li>
</ul>
<p>下面，以 Coding 迁移到 GitHub 为例。</p>
<h3 id="toc-heading-4">A. Git Bash操作</h3>
<p><strong>1. 在 GitHub 建立新仓库</strong></p>
<p>在 GitHub 中新建一个同名项目（不同名也可以），不要添加 <code>README.md</code>，以及任何 <code>License</code> 和 <code>.gitignore</code> 文件，只需要新建一个空的仓库。</p>
<p>只需要一个空的仓库。</p>
<p><strong>2. 克隆 Coding 上的项目</strong></p>
<p>将 Coding 上想要迁移的项目完整克隆到本地。</p>
<p>本地执行</p>
<pre><code>git clone https://git.coding.net/winyuan/blog.git  --bare
</code></pre>
<p><strong>3. 将克隆下来的仓库推送到GitHub</strong></p>
<p>克隆完成后，将仓库推送到 GitHub。</p>
<p>使用新仓库页面提供的仓库地址（web URL），推送所有的分支和对象</p>
<pre><code>cd blog.git
git push https://github.com/winyuan/blog.git --all
</code></pre>
<p><strong>4. 完成后，再执行推送所有的Tags</strong></p>
<pre><code>git push https://github.com/winyuan/blog.git --tags
</code></pre>
<p>这样，整个仓库就全部迁移到 GitHub 了，如果这些commit中的邮箱在GitHub配置中，可以看到小绿点也一起迁移过来了。</p>
<h3 id="toc-heading-5">B. TortoiseGit 操作</h3>
<p>这种简单的操作我不是很喜欢用可视化工具，不过这里也介绍下怎么用「小乌龟」来完成仓库的迁移。</p>
<p><strong>1. 在 GitHub 建立新仓库</strong></p>
<p>同上，不赘述了。</p>
<p><strong>2. 克隆 Coding 上的项目</strong></p>
<p>同上，不赘述了。</p>
<p><strong>3. 将克隆下来的仓库推送到 GitHub</strong></p>
<p>进入项目文件夹，鼠标右键 -&gt; Git Sync…</p>
<div><img alt="TortoiseGit同步" src="https://www.wenyuanblog.com/medias/blogimages/TortoiseGit_Sync.png" data-original="/medias/blogimages/TortoiseGit_Sync.png" /></div>
<p>点击 Manage。<br />
<img alt="TortoiseGit同步-管理" src="https://www.wenyuanblog.com/medias/blogimages/TortoiseGit_Sync_Manage.png" width="500" height="300" align="center" data-original="/medias/blogimages/TortoiseGit_Sync_Manage.png" /><br />
填写 GitHub 远程仓库的信息，并 Add New/Save，应用，确认。<br />
<img alt="TortoiseGit同步-管理-远程信息" src="https://www.wenyuanblog.com/medias/blogimages/TortoiseGit_Sync_Manage_Remote.png" width="500" height="300" align="center" data-original="/medias/blogimages/TortoiseGit_Sync_Manage_Remote.png" /><br />
Remote URL 选则刚刚添加的 gitHub，然后 Push。<br />
<img alt="TortoiseGit同步-管理-推送" src="https://www.wenyuanblog.com/medias/blogimages/TortoiseGit_Sync_Manage_Push.png" width="500" height="300" align="center" data-original="/medias/blogimages/TortoiseGit_Sync_Manage_Push.png" /><br />
最后再提交 Tags.<br />
<img alt="TortoiseGit同步-管理-推送标签" src="https://www.wenyuanblog.com/medias/blogimages/TortoiseGit_Sync_Manage_Push_tags.png" data-original="/medias/blogimages/TortoiseGit_Sync_Manage_Push_tags.png" /></p>
<p>&nbsp;</p>
<h2 id="toc-heading-6">四、git命令区别</h2>
<p>上面在推送代码至 GitHub（新仓库）时，我们用到了下面这个命令：<br />
<code>git push https://github.com/winyuan/blog.git --all</code><br />
其实还有另外一个命令：<br />
<code>git push https://github.com/winyuan/blog.git --mirror</code></p>
<p>关于这两个命令的区别，可以参见<a title="Git push --all vs --mirror" href="https://stackoverflow.com/questions/49343025/git-push-all-vs-mirror" target="_0" rel="external nofollow noopener noreferrer">Git push –all vs –mirror</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eavea.com/blog/index.php/gitqianyicangkubingbaoliucommitjilu.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git提交信息规范</title>
		<link>http://www.eavea.com/blog/index.php/gittijiaoxinxiguifan.html</link>
		<comments>http://www.eavea.com/blog/index.php/gittijiaoxinxiguifan.html#comments</comments>
		<pubDate>Tue, 14 Apr 2020 06:54:49 +0000</pubDate>
		<dc:creator>eavea</dc:creator>
				<category><![CDATA[技术周边]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[规范]]></category>

		<guid isPermaLink="false">http://www.eavea.com/blog/?p=34</guid>
		<description><![CDATA[Git提交信息规范 无论是个人项目还是在团队协作中，commit message 都应该清晰明了，遵守一定规范 [&#8230;]]]></description>
				<content:encoded><![CDATA[<div>Git提交信息规范</div>
<blockquote><p>无论是个人项目还是在团队协作中，commit message 都应该清晰明了，遵守一定规范。<br />
目前，社区有多种 commit message 的写法规范。本文介绍 Angular规范，这是目前使用最广的写法，比较合理和系统化，并且有配套的工具。</p></blockquote>
<h2 id="toc-heading-1">一、格式化 commit message 的目的</h2>
<ul>
<li>提供更多的历史信息，方便快速浏览。</li>
<li>可以过滤某些 commit（比如文档改动），便于快速查找信息。</li>
<li>可以直接从 commit 生成 Change log。</li>
</ul>
<h2 id="toc-heading-2">二、commit message 的格式</h2>
<p>每次提交，commit message 都包括三个部分：Header，Body 和 Footer。</p>
<div>bash<i></i><i></i></div>
<pre><code>&lt;type&gt;(&lt;scope&gt;): &lt;subject&gt; # header
# 空一行
&lt;body&gt;
# 空一行
&lt;footer&gt; 
</code></pre>
<p>其中，Header 是必需的，Body 和 Footer 可以省略。<br />
不管是哪一个部分，任何一行都不得超过 72 个字符（或 100 个字符）。这是为了避免自动换行影响美观。</p>
<h3 id="toc-heading-3">1. Header</h3>
<p>Header部分只有一行，包括三个字段：type（必需）、scope（可选）和subject（必需）。</p>
<p><strong>(1) type </strong></p>
<p>type用于说明 commit 的类别，只允许使用下面7个标识：</p>
<ul>
<li><code>feat</code>：新功能（feature）</li>
<li><code>fix</code>：修补bug</li>
<li><code>docs</code>：文档（documentation）</li>
<li><code>style</code>：格式（不影响代码运行的变动）</li>
<li><code>refactor</code>：重构（即不是新增功能，也不是修改bug的代码变动）</li>
<li><code>test</code>：增加测试</li>
<li><code>chore</code>：构建过程或辅助工具的变动</li>
</ul>
<p>如果 type 为 feat 和 fix，则该 commit 将肯定出现在 Change log 之中。其他情况（docs、chore、style、refactor、test）由你决定，要不要放入 Change log，建议是不要。</p>
<p><strong>(2) scope </strong></p>
<p>用于说明 commit 影响的范围，比如数据层、控制层、视图层等等，视项目不同而不同。</p>
<p><strong>(3) subject </strong></p>
<p>subject 是 commit 目的的简短描述，不超过 50 个字符。</p>
<ul>
<li>以动词开头，使用第一人称现在时，比如 change，而不是 changed 或 changes。</li>
<li>第一个字母小写。</li>
<li>结尾不加句号（.）。</li>
</ul>
<h3 id="toc-heading-4">2. Body</h3>
<p>用于对本次 commit 的详细描述，可以分成多行。下面是一个范例：</p>
<div>bash<i></i><i></i></div>
<pre><code>More detailed explanatory text, if necessary.  Wrap it to 
about 72 characters or so. 

Further paragraphs come after blank lines.

- Bullet points are okay, too
- Use a hanging indent
</code></pre>
<p>有两个注意点。<br />
(1) 使用第一人称现在时，比如使用 change 而不是 changed 或 changes。<br />
(2) 应该说明代码变动的动机，以及与以前行为的对比。</p>
<h3 id="toc-heading-5">3. Footer</h3>
<p>Footer 部分只用于两种情况。</p>
<p><strong>(1) 不兼容变动 </strong></p>
<p>如果当前代码与上一个版本不兼容，则 Footer 部分以 <code>BREAKING CHANGE</code> 开头，后面是对变动的描述、以及变动理由和迁移方法。</p>
<div>bash<i></i><i></i></div>
<pre><code>BREAKING CHANGE: isolate scope bindings definition has changed.

To migrate the code follow the example below:

Before:

scope: {
  myAttr: 'attribute',
}

After:

scope: {
  myAttr: '@',
}

The removed `inject` wasn't generaly useful for directives so there should be no code using it.
</code></pre>
<p><strong> (2) 关闭 Issue </strong></p>
<p>如果当前 commit 针对某个issue，那么可以在 Footer 部分关闭这个 issue 。</p>
<div>bash<i></i><i></i></div>
<pre><code>Closes #234
</code></pre>
<p>也可以一次关闭多个 issue 。</p>
<div>bash<i></i><i></i></div>
<pre><code>Closes #123, #245, #992
</code></pre>
<h3 id="toc-heading-6">4. Revert（可忽视）</h3>
<p>还有一种特殊情况，如果当前 commit 用于撤销以前的 commit，则必须以 <code>revert:</code> 开头，后面跟着被撤销 Commit 的 Header。</p>
<div>bash<i></i><i></i></div>
<pre><code>revert: feat(pencil): add 'graphiteWidth' option

This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
</code></pre>
<p>Body 部分的格式是固定的，必须写成 <code>This reverts commit &lt;hash&gt;.</code>，其中的 hash 是被撤销 commit 的 SHA 标识符。</p>
<p>如果当前 commit 与被撤销的 commit，在同一个发布（release）里面，那么它们都不会出现在 Change log 里面。如果两者在不同的发布，那么当前 commit，会出现在 Change log 的Reverts小标题下面。</p>
<h2 id="toc-heading-7">三、提交频率</h2>
<p>关于什么时候提交一次：<br />
每次你写完一个功能的时候，就应该做一次提交（这个提交是提交到本地的 git 库中）。<br />
当<br />
然，这里的写完表示的是你的这个功能是没有问题的。</p>
<h2 id="toc-heading-8">四、Angular规范</h2>
<p><a href="https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#heading=h.greljkmo14y0" target="_0" rel="external nofollow noopener noreferrer">Angular规范</a>见上图：</p>
<div><img alt="Angular规范" src="https://www.wenyuanblog.com/medias/blogimages/git_commit_message_angular.png" data-original="/medias/blogimages/git_commit_message_angular.png" /></div>
<p>&nbsp;</p>
<h2 id="toc-heading-9">附：团队协作风格指南</h2>
<p>在团队协作中，不管有多少人共同参与同一项目，我们期望每一行代码都像是同一个人编写的。因此需要永远遵循同一套编码规范。<br />
我基于国内大厂规范，整理了一套<a title="团队协作风格指南" href="https://github.com/winyuan/style-guide" target="_0" rel="external nofollow noopener noreferrer">《团队协作风格指南》</a>，仅供参考。<br />
整理自<a href="http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html" target="_0" rel="external nofollow noopener noreferrer">《Commit message 和 Change log 编写指南》-阮一峰</a><br />
参考<a href="https://segmentfault.com/a/1190000004282514" target="_0" rel="external nofollow noopener noreferrer">［译］AngularJS Git提交信息规范</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eavea.com/blog/index.php/gittijiaoxinxiguifan.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
