{"id":948,"date":"2023-06-12T10:02:50","date_gmt":"2023-06-12T02:02:50","guid":{"rendered":"https:\/\/swordofmorning.com\/?p=948"},"modified":"2025-10-09T13:55:19","modified_gmt":"2025-10-09T05:55:19","slug":"git-02","status":"publish","type":"post","link":"https:\/\/swordofmorning.com\/index.php\/2023\/06\/12\/git-02\/","title":{"rendered":"Git 02 Advanced Tutorial"},"content":{"rendered":"<h2>\u4e00\u3001Commit<\/h2>\n<h3>1.1 Add Commit<\/h3>\n<p>&emsp;&emsp;\u5bf9\u4e8e\u65b0\u589e\u6587\u4ef6A\u3001B\u548cC\uff0c\u5c3d\u91cf\u91c7\u7528\u5206\u7ec4\u63d0\u4ea4\u7684\u65b9\u5f0f\uff0c\u800c\u4e0d\u662f<code>add --all<\/code>\u3002\u4f8b\u5982\uff0cA\u548cB\u662f\u4fee\u6539\u4e86\u67d0\u4e00\u4e2a\u529f\u80fd\uff0cC\u4fee\u6539\u4e86\u53e6\u4e00\u4e2a\u529f\u80fd\uff0c\u5219\u4f7f\u7528\u4e24\u6b21commit\uff0c\u6bcf\u4e00\u6b21commit\u5907\u6ce8\u5176\u4fee\u6539\u7684\u5185\u5bb9\u3002<\/p>\n<h3>1.2 Patch<\/h3>\n<p>&emsp;&emsp;\u5047\u8bbe\u6211\u4eec\u7684\u4e00\u4e2a\u6587\u4ef6\u5176\u505a\u4e86\u591a\u4e2a\u90e8\u5206\u7684\u4fee\u6539\uff0c\u5e76\u4e14\u5f15\u5165\u4e86\u6211\u4eec\u81ea\u5df1\u7684\u8c03\u8bd5\u8f93\u51fa\u3002\u76f4\u63a5\u4f7f\u7528add\u4f1a\u6dfb\u52a0\u5168\u90e8\u7684\u4fee\u6539\uff0c\u4f7f\u7528<code>add -p<\/code>\u5219\u53ef\u4ee5\u6307\u5b9a\u5176\u63d0\u4ea4\u7684\u90e8\u5206\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-diff\">@@ -1,16 +1,31 @@\n #include &lt;stdio.h&gt;\n\n+void fun1()\n+{\n+       printf(&quot;before hello world\\n&quot;);\n+}\n+\n void demo()\n {\n        ;\n }\n\n+void fun2()\n+{\n+       printf(&quot;after hello world\\n&quot;);\n+}\n+\n int main()\n {\n+       fun1();\n        printf(&quot;hello world\\n&quot;);\n+       printf(&quot;debug %s %d\\n&quot;, __func__, __LINE__);\n        printf(&quot;hello world\\n&quot;);\n        printf(&quot;hello world\\n&quot;);\n        printf(&quot;hello world\\n&quot;);\n+       printf(&quot;debug %s %d\\n&quot;, __func__, __LINE__);\n        printf(&quot;hello world\\n&quot;);\n+       fun2();\n        demo();\n+       printf(&quot;debug %s %d\\n&quot;, __func__, __LINE__);\n }<\/code><\/pre>\n<p>\u5982\u679c\u6211\u4eec\u53ea\u60f3\u63d0\u4ea4fun1\u7684\u5185\u5bb9\uff0c\u5219\u4f7f\u7528<code>-p<\/code>\u6765\u6307\u5b9a\u9700\u8981\u63d0\u4ea4\u7684\u90e8\u5206\u3002\u8f93\u5165<code>git add -p test.c<\/code>\uff0cgit\u4f1a\u5c06\u4ee3\u7801\u62c6\u5206\u4e3a\u591a\u4e2a\u7247\u6bb5\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u7247\u6bb5\u6709\u5982\u4e0b\u547d\u4ee4\u9009\u62e9\uff08git\u4f1a\u63d0\u793a\u4f60<code>Stage this hunk [y,n,q,a,d,\/,s,e,?]?<\/code>\uff09\uff1a<\/p>\n<pre><code>y - stage this hunk\nn - do not stage this hunk\nq - quit; do not stage this hunk or any of the remaining ones\na - stage this hunk and all later hunks in the file\nd - do not stage this hunk or any of the later hunks in the file\ng - select a hunk to go to\n\/ - search for a hunk matching the given regex\nj - leave this hunk undecided, see next undecided hunk\nJ - leave this hunk undecided, see next hunk\nk - leave this hunk undecided, see previous undecided hunk\nK - leave this hunk undecided, see previous hunk\ns - split the current hunk into smaller hunks\ne - manually edit the current hunk\n? - print help\n\ny - \u6682\u5b58\u6b64\u533a\u5757\nn - \u4e0d\u6682\u5b58\u6b64\u533a\u5757\nq - \u9000\u51fa\uff1b\u4e0d\u6682\u5b58\u5305\u62ec\u6b64\u5757\u5728\u5185\u7684\u5269\u4f59\u7684\u533a\u5757\na - \u6682\u5b58\u6b64\u5757\u4e0e\u6b64\u6587\u4ef6\u540e\u9762\u6240\u6709\u7684\u533a\u5757\nd - \u4e0d\u6682\u5b58\u6b64\u5757\u4e0e\u6b64\u6587\u4ef6\u540e\u9762\u6240\u6709\u7684 \u533a\u5757\ng - \u9009\u62e9\u5e76\u8df3\u8f6c\u81f3\u4e00\u4e2a\u533a\u5757\n\/ - \u641c\u7d22\u4e0e\u7ed9\u5b9a\u6b63\u5219\u8868\u8fbe\u793a\u5339\u914d\u7684\u533a\u5757\nj - \u6682\u4e0d\u51b3\u5b9a\uff0c\u8f6c\u81f3\u4e0b\u4e00\u4e2a\u672a\u51b3\u5b9a\u7684\u533a\u5757\nJ - \u6682\u4e0d\u51b3\u5b9a\uff0c\u8f6c\u81f3\u4e00\u4e2a\u533a\u5757\nk - \u6682\u4e0d\u51b3\u5b9a\uff0c\u8f6c\u81f3\u4e0a\u4e00\u4e2a\u672a\u51b3\u5b9a\u7684\u533a\u5757\nK - \u6682\u4e0d\u51b3\u5b9a\uff0c\u8f6c\u81f3\u4e0a\u4e00\u4e2a\u533a\u5757\ns - \u5c06\u5f53\u524d\u7684\u533a\u5757\u5206\u5272\u6210\u591a\u4e2a\u8f83\u5c0f\u7684\u533a\u5757\ne - \u624b\u52a8\u7f16\u8f91\u5f53\u524d\u7684\u533a\u5757\n? - \u8f93\u51fa\u5e2e\u52a9<\/code><\/pre>\n<h3>1.3 Message<\/h3>\n<p>&emsp;&emsp;\u5bf9\u4e8e\u63d0\u4ea4\uff0c\u5efa\u8bae\u4f7f\u7528<code>git commit<\/code>\u6765\u8be6\u7ec6\u63cf\u8ff0\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u4f7f\u7528<code>git commit -m &quot;message&quot;<\/code>\u7684\u65b9\u5f0f\u3002\u751f\u6210\u7684\u63d0\u4ea4\u6587\u4ef6\u662f<code>.\/git\/COMMIT_EDITMSG<\/code>\u3002\u5bf9\u4e8e\u63cf\u8ff0\u6587\u4ef6\uff0c\u4e00\u822c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre><code>type(scope): subject\n\nbody\n\nfooter\n\n&lt;!-- git\u81ea\u52a8\u751f\u6210\u7684\u5185\u5bb9 --&gt;<\/code><\/pre>\n<p>\u5176\u4e2d<code>type(scope): subject<\/code>\u53c8\u88ab\u79f0\u4e3aheader\uff0ctype\u7684\u7c7b\u578b\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>feat\uff1a\u65b0\u529f\u80fd\uff08feature\uff09<\/li>\n<li>fix\uff1a\u4fee\u8865bug<\/li>\n<li>docs\uff1a\u6587\u6863\uff08documentation\uff09<\/li>\n<li>style\uff1a \u683c\u5f0f\uff08\u4e0d\u5f71\u54cd\u4ee3\u7801\u8fd0\u884c\u7684\u53d8\u52a8\uff09<\/li>\n<li>refactor\uff1a\u91cd\u6784\uff08\u5373\u4e0d\u662f\u65b0\u589e\u529f\u80fd\uff0c\u4e5f\u4e0d\u662f\u4fee\u6539bug\u7684\u4ee3\u7801\u53d8\u52a8\uff09<\/li>\n<li>test\uff1a\u589e\u52a0\u6d4b\u8bd5<\/li>\n<li>chore\uff1a\u6784\u5efa\u8fc7\u7a0b\u6216\u8f85\u52a9\u5de5\u5177\u7684\u53d8\u52a8<\/li>\n<\/ul>\n<p><code>scope<\/code>\u7528\u4e8e\u8bf4\u660ecommit\u5f71\u54cd\u7684\u8303\u56f4\uff0c\u6bd4\u5982\u6570\u636e\u5c42\u3001\u63a7\u5236\u5c42\u3001\u89c6\u56fe\u5c42\u7b49\u7b49\uff0c\u89c6\u9879\u76ee\u4e0d\u540c\u800c\u4e0d\u540c\u3002<code>subject<\/code>\u4e3a\u7b80\u77ed\u7684\u63cf\u8ff0\u5185\u5bb9\uff0c\u540c<code>-m &quot;message&quot;<\/code>\u4e2d\u7684\u5185\u5bb9\u3002<code>body<\/code>\u4e3a\u4e3b\u8981\u63cf\u8ff0\u5185\u5bb9\uff0c<code>footer<\/code>\u7528\u4e8e\u4e0d\u517c\u5bb9\u53d8\u52a8\u548c\u5173\u95edissue\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u53c2\u8003\uff1a<\/p>\n<pre><code>feat: new funcion in hello\n\nAdd new function, which return 5.\n- hello.h add: int func()\n- hello.c change the cout\n\n# Please enter the commit message for your changes. Lines starting\n# with &#039;#&#039; will be ignored, and an empty message aborts the commit.\n# On branch master\n# Changes to be committed:\n#   modified:   hello.cpp\n#   new file:   hello.h\n#<\/code><\/pre>\n<h2>\u4e8c\u3001Branch<\/h2>\n<p>&emsp;&emsp;\u63a8\u8350\u4f7f\u7528\uff1a<\/p>\n<pre><code>master ................................................... -&gt; master\n       -&gt; dev                      -&gt; dev            -&gt; dev\n             -&gt; feature -&gt; feature        -&gt; feature<\/code><\/pre>\n<h2>\u4e09\u3001gitignore<\/h2>\n<p>&emsp;&emsp;\u5047\u8bbe\u6211\u4eec\u73b0\u5728\u6709\u51e0\u4e2a\u6587\u4ef6\u4e0e\u76ee\u5f55\uff1a<\/p>\n<pre><code>build\/\nsrc\/\nCMakeLists.txt<\/code><\/pre>\n<p>\u73b0\u5728\u6211\u4eec\u4e0d\u9700\u8981\u63d0\u4ea4<code>build\/<\/code>\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u4e00\u4e2a<code>.gitignore<\/code>\u6587\u4ef6\uff0c\u6587\u4ef6\u6392\u5217\u5982\u4e0b\uff1a<\/p>\n<pre><code>build\/\nsrc\/\nCMakeLists.txt\n.gitignore<\/code><\/pre>\n<p><code>.gitignore<\/code>\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code>.gitignore\nbuild\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001Commit 1.1 Add Commit &emsp;&emsp;\u5bf9\u4e8e\u65b0\u589e\u6587\u4ef6A\u3001B\u548cC\uff0c\u5c3d\u91cf\u91c7\u7528\u5206\u7ec4\u63d0\u4ea4\u7684\u65b9\u5f0f\uff0c\u800c\u4e0d\u662fad &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/948"}],"collection":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/comments?post=948"}],"version-history":[{"count":1,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/948\/revisions"}],"predecessor-version":[{"id":951,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/948\/revisions\/951"}],"wp:attachment":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/media?parent=948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/categories?post=948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/tags?post=948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}