{"id":1128,"date":"2014-01-16T14:40:00","date_gmt":"2014-01-16T06:40:00","guid":{"rendered":"http:\/\/www.dogeye.net\/?p=1128"},"modified":"2014-01-16T14:40:00","modified_gmt":"2014-01-16T06:40:00","slug":"%e4%bd%bf%e7%94%a8git%e7%9a%84submodule%e5%8a%9f%e8%83%bd%e7%ae%a1%e7%90%86%e7%ac%ac%e4%b8%89%e6%96%b9%e5%ba%93","status":"publish","type":"post","link":"https:\/\/ykyi.net\/?p=1128","title":{"rendered":"\u4f7f\u7528Git\u7684submodule\u529f\u80fd\u7ba1\u7406\u7b2c\u4e09\u65b9\u5e93"},"content":{"rendered":"<p align=\"left\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">\u7528Git\u7684Submodule\u529f\u80fd\u6765\u7ba1\u7406\u4ee3\u7801\u4e2d\u4f7f\u7528\u7684\u5176\u5b83\u5e93\uff0c\u8fd8\u662f\u6ee1\u65b9\u4fbf\u7684\u3002\u4e3b\u8981\u7528\u5230\u4e09\u4e2a\u547d\u4ee4:<\/span><\/span><\/p>\n<p align=\"left\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">Git submodule add, git submodule init, git submodule update.<\/span><\/span><\/p>\n<p align=\"left\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">git submodule init to initialize your local configuration file and git submodule update to fetch all the data from that project and check out the appropriate commit listed in your superproject.<\/span><\/span><\/p>\n<p align=\"left\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">\u8fd8\u6709\u4e24\u4e2a\u67e5\u770b\u76f8\u5173\u4fe1\u606f\u7684\u547d\u4ee4git submodule summary,\u548c git submodule status.<\/span><\/span><\/p>\n<p align=\"left\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">Git\u7684submodule\u529f\u80fd\u5e26\u6765\u7684\u597d\u5904\u548c\u574f\u5904\u90fd\u5f88\u591a\uff0c\u7f51\u4e0a\u6709\u5927\u91cf\u7684\u8d34\u5b50\u53cd\u5bf9\u4f7f\u7528git submodule\u3002<\/span><\/span><\/p>\n<p align=\"left\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">\u6211\u89c9\u6709\u9650\u5236\u5730\uff0c\u5728\u4ee5\u4e0b\u573a\u666f\u7528git submodule\u7ba1\u7406\u7b2c\u4e09\u65b9\u5e93\u7684\u4ee3\u7801\u8fd8\u662f\u5f88\u4e0d\u9519\u3002<\/span><\/span><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">1.&nbsp;&nbsp;&nbsp; \u4f60\u4f7f\u7528\u7684\u7b2c\u4e09\u65b9\u5e93\u66f4\u65b0\u975e\u5e38\u6162\uff0c\u751a\u81f3\u4e0d\u66f4\u65b0\uff0c\u5b83\u7684\u63a5\u53e3\u5f88\u7a33\u5b9a\u3002\u6bd4\u5982\uff1a\u7ba1\u7406vim\u7684\u63d2\u4ef6\u4eec\u3002<\/span><\/span><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">2.&nbsp;&nbsp;&nbsp; \u7b2c\u4e09\u65b9\u5e93\u4ee5\u6bd4\u8f83\u56fa\u5b9a\u7684\u5468\u671f\u66f4\u65b0\u3002\u4e8e\u662f\uff0c\u8fc7\u4e00\u6bb5\u65f6\u95f4\u518d\u628a\u4e0a\u6e38\u7684\u4ee3\u7801\u62c9\u5230submodule\u4e0a\u6765\u3002<\/span><\/span><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">3.&nbsp;&nbsp;&nbsp; \u7b2c\u4e09\u65b9\u5e93\u867d\u7136\u66f4\u65b0\u5f88\u5feb\uff0c\u4f46\u6211\u8fc7\u4e00\u6bb5\u65f6\u95f4\u624d\u62c9\u53d6\u4e0a\u6e38\u4ee3\u7801\u4e5f\u65e0\u6240\u8c13\u3002<\/span><\/span><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">\u5982\u679c\u5355\u5f00\u4e00\u4e2agit clone\u7ba1\u7406\u7b2c\u4e09\u65b9\u5e93\uff0c\u4e0e\u81ea\u5df1\u7684\u9879\u76ee\u5e73\u884c\uff0c\u5f53\u7136\u4e5f\u662f\u53ef\u4ee5\u7684\u3002\u4f46\u8fd9\u6837\u6709\u4e2a\u95ee\u9898\u662f\uff0c\u522b\u4ebagit clone\u4e86\u4f60\u7684\u9879\u76ee\uff0c\u8fd8\u9700\u8981\u518dgit clone\u4e00\u6b21\u4f60\u7684\u9879\u76ee\u4f9d\u8d56\u7684\u9879\u76ee\uff0c\u5e76\u653e\u5728\u9002\u5f53\u7684\u76f8\u5bf9\u8def\u5f84\u4e0a\u3002\u800c\u4f7f\u7528git submodule *\u65f6\uff0c\u4f60\u7684\u9879\u76ee\u548c\u4f60\u4f9d\u8d56\u7684\u5e93\u662f\u5c42\u7ea7\u5173\u7cfb\uff0c\u6709\u6761\u7406\u5f97\u591a\u3002<\/span><\/span><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\">&nbsp;<\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">\u8fd8\u6709\u4e00\u79cd\u65b9\u5f0f\u662f\u628a\u7b2c\u4e09\u65b9\u5e93\u7684\u4ee3\u7801\u5408\u5e76\u5230\u81ea\u5df1\u7684\u4ee3\u7801\u4e2d\u3002\u8fd9\u6837\u505a\u7684\u574f\u5904\u662f\u663e\u800c\u6613\u89c1\u7684\uff0c\u5982\u679c\u4f60\u8981\u5408\u5e76\u4e0a\u6e38\u4ee3\u7801\u7684FIX\u6216\u529f\u80fd\u52a0\u5f3a\uff0c\u90fd\u975e\u5e38\u7684\u9ebb\u70e6\u3002\u5927\u591a\u6570\u4eba\u662f\u4e0d\u4f1a\u53bb\u505a\u8fd9\u4e2a\u540c\u6b65\u7684\uff0c\u4e8e\u662f\u4ee3\u7801\u4f1a\u88ab\u624b\u52a8\u590d\u5236\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u7ec6\u5fae\u6539\u52a8\u5206\u6563\u5728\u5404\u4e2a\u4e0d\u540c\u7684\u9879\u76ee\u7684\u76f8\u540c\/\u76f8\u8fd1\u4ee3\u7801\u4e2d\u3002\u4e00\u7247\u6df7\u4e71&hellip;.<\/span><\/span><\/p>\n<p align=\"left\"><span style=\"font-size:14px;\"><strong>\u4f7f\u7528Git Submodule\u65f6\u5ffd\u7565Submodule\u7684\u6539\u52a8\uff1a<\/strong><\/span><\/p>\n<p align=\"left\">\u5982\u679csubmodule\u4e2d\u6709\u751f\u6210\u65b0\u6587\u4ef6\u3002\u5728\u7236\u5de5\u7a0b(superproject)\u4e2d\u7528git status\uff0c\u5c31\u603b\u4f1a\u63d0\u9192\u4f60git submodule\u5b50\u6a21\u5757\u6709\u8fd8\u6ca1\u88ab\u8ddf\u8e2a\u7684\u6587\u4ef6\u3002<\/p>\n<p align=\"left\">\u6bd4\u5982\uff1a\u4e00\u6b21make\u4f1a\u751f\u6210\u5f88\u591a.o\uff0c.dep\u6587\u4ef6\u3002\u6bd4\u5982\u7528git submodule\u7ba1\u7406vim\u63d2\u4ef6\u4f1a\u751f\u6210\u5404\u79cd\u4e34\u65f6\u6587\u4ef6\u3002\u4f60\u4e0d\u60f3\u8ba9git status\u63d0\u9192\u4f60\uff0c\u8fd9\u591a\u4e48\u70e6\u4eba\u554a\u3002<\/p>\n<p align=\"left\">\u5982\u4e0b\uff0cgit status\u603b\u63d0\u9192\u6211cpp-iniparser\u5b50\u6a21\u5757\u6709\u672a\u8ddf\u8e2a\u7684\u6587\u4ef6\uff1a<\/p>\n<p align=\"left\" style=\"margin-left: 40px;\">root@vicarious:\/home\/kamus\/projs\/horoscope# git status<br \/>\n\t# On branch dev<br \/>\n\t# Changes not staged for commit:<br \/>\n\t# &nbsp; (use &quot;git add &lt;file&gt;&#8230;&quot; to update what will be committed)<br \/>\n\t# &nbsp; (use &quot;git checkout &#8212; &lt;file&gt;&#8230;&quot; to discard changes in working directory)<br \/>\n\t# &nbsp; (commit or discard the untracked or modified content in submodules)<br \/>\n\t#<br \/>\n\t#&nbsp;&nbsp; &nbsp;modified: &nbsp; configuration.cpp<br \/>\n\t#&nbsp;&nbsp; &nbsp;modified: &nbsp; configuration.h<br \/>\n\t#&nbsp;&nbsp; &nbsp;modified: &nbsp; cpp-iniparser (untracked content)<\/p>\n<p align=\"left\">\u5982\u4f55\u8ba9git\u5ffd\u7565\u5230\u8fd9\u4e2a\u63d0\u9192\u5462\uff0c\u89e3\u51b3\u65b9\u6cd5\u662f\u7f16\u8f91\u7236\u5de5\u7a0b\u4e2d\u7684.gitmodules\u6587\u4ef6\u3002\u52a0\u5165 ignore = dirty\u3002\u5982\u4e0b\uff1a<\/p>\n<p align=\"left\" style=\"margin-left: 40px;\">[submodule &#8220;cpp-iniparser&#8221;]<br \/>\n\t&nbsp;&nbsp; &nbsp;path = cpp-iniparser<br \/>\n\t&nbsp;&nbsp; &nbsp;url = https:\/\/github.com\/zausiu\/cpp-iniparser<br \/>\n\t&nbsp;&nbsp; &nbsp;ignore = dirty<\/p>\n<p style=\"margin-left: 40px;\">&nbsp;<\/p>\n<p align=\"left\"><span style=\"font-size:18px;\"><strong style=\"font-size: 14px; line-height: 1.6em;\">git clone\u7684\u4ee3\u7801\u91cc\u9762\u6709submodule\uff0c\u76ee\u5f55\u662f\u7a7a\u7684\u3002\u600e\u4e48clone\u5b50\u6a21\u5757submodule\u7684\u4ee3\u7801<\/strong><\/span><\/p>\n<p>\u5bf9\u4e8egit 1.6.5\u4ee5\u540e\u7684\u7248\u672c\uff0c\u4f7f\u7528clone\u7684&#8211;recursive\uff0c\u5982\u4e0b\uff1a<\/p>\n<p>git clone &#8211;recursive git:\/\/github.com\/foo\/bar.git<\/p>\n<p>\u5bf9\u4e8e\u8001\u65e7\u7684git\uff0c\u53ef\u4ee5\u4f7f\u7528git submodule init\u548cgit submodule update<\/p>\n<p>\u6bd4\u5982\uff1a<\/p>\n<p>git clone git:\/\/github.com\/foo\/bar.git<\/p>\n<p>\/\/ \u6b64\u5904\u53ef\u4ee5\u8981\u5148cd\u5230\u5b50\u6a21\u5757\u7684\u76ee\u5f55\uff0c\u8f83\u65b0\u7684git\u5219\u4e0d\u9700\u8981cd<br \/>\n\tgit submodule init<br \/>\n\tgit submodule update<\/p>\n<p><strong style=\"font-size: 13px; line-height: 1.6em;\"><span style=\"font-size: 14px;\"><span style=\"font-family: arial, helvetica, sans-serif;\">git submodule status\u663e\u793a\u7684HASH\u4ee3\u7801\u524d\u7684\u6a2a\u6760-\u662f\u4ec0\u4e48\u610f\u601d<\/span><\/span><\/strong><\/p>\n<p><span style=\"font-size: 14px;\"><span style=\"font-family: arial, helvetica, sans-serif;\">\u8868\u793a\u5bf9\u5e94\u7684\u5b50\u6a21\u5757submodule\u8fd8\u6ca1\u6709\u4e0b\u8f7d\u5230\u672c\u5730\u3002<\/span><\/span><\/p>\n<p><strong style=\"font-size: 13px; line-height: 1.6em;\"><span style=\"font-size: 14px;\"><span style=\"font-family: arial, helvetica, sans-serif;\">git\u600e\u4e48\u5220\u9664\u4e00\u4e2a\u5b50\u6a21\u5757submodule<\/span><\/span><\/strong><\/p>\n<p><span style=\"font-size: 14px;\"><span style=\"font-family: arial, helvetica, sans-serif;\">step 1: \u5220\u9664.gitmodules\u6587\u4ef6\u4e2d\u5b50\u6a21\u5757\u7684\u5bf9\u5e94\u9879<\/span><\/span><\/p>\n<p><span style=\"font-size: 14px;\"><span style=\"font-family: arial, helvetica, sans-serif;\">step 2: \u5220\u9664.git\/config\u6587\u4ef6\u4e2d\u5b50\u6a21\u5757\u7684\u5bf9\u5e94\u9879<\/span><\/span><\/p>\n<p><span style=\"font-size: 14px;\"><span style=\"font-family: arial, helvetica, sans-serif;\">step 3:git rm &#8230;<\/span><\/span><\/p>\n<p><strong><span style=\"font-size: 14px;\"><span style=\"font-family: arial, helvetica, sans-serif;\">git submoduler\u7684160000\u4ec0\u4e48\u610f\u601d\uff1f<\/span><\/span><\/strong><\/p>\n<p><font face=\"arial, helvetica, sans-serif\"><span style=\"font-size: 14px; line-height: 14.9333333969116px;\">\u5f53\u5728\u5305\u542b\u6709submodule\u7684\u7236\u5de5\u7a0b\u4e2dgit commit\u4ee5\u540e\uff0c\u4f1a\u6709\u7c7b\u4f3ccreate mode 160000 submoduleName \u7684\u63d0\u793a\uff0c\u8fd9\u4e2a160000\u7684\u610f\u601d\u662f\uff1athis is a special mode in git that basically means you&#39;re recording a commit as a commit as a directory entry rather than a subdirectory or a file.<\/span><\/font><\/p>\n<p><strong><font face=\"arial, helvetica, sans-serif\"><span style=\"font-size: 14px; line-height: 14.9333333969116px;\">\u5176\u5b83\u6709\u7528\u7684git submodule\u547d\u4ee4:<\/span><\/font><\/strong><\/p>\n<p>git diff &#8211;submodule: you can see that the submodule was updated and get a list of commits that were added to it<\/p>\n<p>git submodule update &#8211;remote means: git goes into your submodules and fetch(git fetch) and update(git merge origin\/master) for you.<\/p>\n<p>git submodule update &#8211;remote &#8211;merge or &#8211;rebase<\/p>\n<p>git submodule foreach &#39;git stash&#39;; git submodule foreach &#39;git checkout -b featureA&#39;<\/p>\n<p align=\"left\"><strong style=\"line-height: 1.6em;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">\u4f7f\u7528Git Submodules\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\uff1aGOTCHA<\/span><\/span><\/strong><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">1.&nbsp;&nbsp;&nbsp; \u5982\u679c\u4f60\u4fee\u6539\u4e86submodule\u7684\u4ee3\u7801\uff0c\u90a3\u5fc5\u987b\u5148commit submodule\u7684\u8fd9\u4e9b\u4fee\u6539\uff0c\u518d\u5230\u7236\u5de5\u7a0b(superproject)\u4e2d\u63d0\u4ea4commit\u3002<\/span><\/span><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">2.&nbsp;&nbsp;&nbsp; Git \u5728\u7236\u5de5\u7a0b\u4e2d\u7528git update\u4f1a\u8986\u76d6\u5b50\u6a21\u5757\u7684\u672a\u63d0\u4ea4\u7684\u66f4\u65b0\u3002<\/span><\/span><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">3.&nbsp;&nbsp;&nbsp; \u5982\u679c\u624b\u52a8\u4fee\u6539\u4e86\u7236\u5de5\u7a0b\u76ee\u5f55\u4e0b\u7684.gitmodules\u6587\u4ef6\uff0c\u90a3\u4e48\u9700\u8981\u7528git submodule sync\u6765\u66f4\u65b0.git\/config\u6587\u4ef6\u4e2d\u7684\u914d\u7f6e\u3002<\/span><\/span><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">4. When run git submodule update, If your forget the &#8211;rebase or &#8211;merge.&nbsp;Git will just update the submodule to whatever is on the server and reset your project to a detached HEAD state.<\/span><\/span><\/p>\n<p align=\"left\" style=\"margin-left:18pt;\"><span style=\"font-size:14px;\"><span style=\"font-family:arial,helvetica,sans-serif;\">copyright ykyi.net<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528Git\u7684Submodule\u529f\u80fd\u6765\u7ba1\u7406\u4ee3\u7801\u4e2d\u4f7f\u7528\u7684\u5176\u5b83\u5e93\uff0c\u8fd8\u662f\u6ee1\u65b9\u4fbf\u7684\u3002\u4e3b\u8981\u7528\u5230\u4e09\u4e2a\u547d\u4ee4: Git submodule add, git submodule init, git submodule update. git submodule init to initialize your local configuration file and git submodule update to fetch all the data from that project and check out the appropriate commit listed in your superproject. \u8fd8\u6709\u4e24\u4e2a\u67e5\u770b\u76f8\u5173\u4fe1\u606f\u7684\u547d\u4ee4git submodule summary,\u548c git submodule status. Git\u7684submodule\u529f\u80fd\u5e26\u6765\u7684\u597d\u5904\u548c\u574f\u5904\u90fd\u5f88\u591a\uff0c\u7f51\u4e0a\u6709\u5927\u91cf\u7684\u8d34\u5b50\u53cd\u5bf9\u4f7f\u7528git submodule\u3002 \u6211\u89c9\u6709\u9650\u5236\u5730\uff0c\u5728\u4ee5\u4e0b\u573a\u666f\u7528git submodule\u7ba1\u7406\u7b2c\u4e09\u65b9\u5e93\u7684\u4ee3\u7801\u8fd8\u662f\u5f88\u4e0d\u9519\u3002 1.&nbsp;&nbsp;&nbsp; \u4f60\u4f7f\u7528\u7684\u7b2c\u4e09\u65b9\u5e93\u66f4\u65b0\u975e\u5e38\u6162\uff0c\u751a\u81f3\u4e0d\u66f4\u65b0\uff0c\u5b83\u7684\u63a5\u53e3\u5f88\u7a33\u5b9a\u3002\u6bd4\u5982\uff1a\u7ba1\u7406vim\u7684\u63d2\u4ef6\u4eec\u3002 2.&nbsp;&nbsp;&nbsp; \u7b2c\u4e09\u65b9\u5e93\u4ee5\u6bd4\u8f83\u56fa\u5b9a\u7684\u5468\u671f\u66f4\u65b0\u3002\u4e8e\u662f\uff0c\u8fc7\u4e00\u6bb5\u65f6\u95f4\u518d\u628a\u4e0a\u6e38\u7684\u4ee3\u7801\u62c9\u5230submodule\u4e0a\u6765\u3002 &hellip; <a href=\"https:\/\/ykyi.net\/?p=1128\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u4f7f\u7528Git\u7684submodule\u529f\u80fd\u7ba1\u7406\u7b2c\u4e09\u65b9\u5e93&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[36],"class_list":["post-1128","post","type-post","status-publish","format-standard","hentry","category-tech_articles","tag-git"],"_links":{"self":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/1128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1128"}],"version-history":[{"count":0,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/1128\/revisions"}],"wp:attachment":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}