{"id":42707,"date":"2024-12-01T13:17:43","date_gmt":"2024-12-01T05:17:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42707\/"},"modified":"2024-12-01T13:17:43","modified_gmt":"2024-12-01T05:17:43","slug":"go-git-%e8%bf%94%e5%9b%9e%e6%9c%aa%e7%9f%a5%e7%9a%84%e7%8a%b6%e6%80%81%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42707\/","title":{"rendered":"go-git \u8fd4\u56de\u672a\u77e5\u7684\u72b6\u6001\u7c7b\u578b"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>go-git \u8fd4\u56de\u672a\u77e5\u7684\u72b6\u6001\u7c7b\u578b<\/span><\/p>\n<h1>go-git \u8fd4\u56de\u672a\u77e5\u7684\u72b6\u6001\u7c7b\u578b<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-25 15:06:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p><span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300ago-git \u8fd4\u56de\u672a\u77e5\u7684\u72b6\u6001\u7c7b\u578b\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span><\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u4f7f\u7528 <code>go-git<\/code> \u5e93\u83b7\u53d6\u5728 <code>git<\/code> \u5b58\u50a8\u5e93\u4e2d\u68c0\u67e5\u7684\u6587\u4ef6\u7684\u72b6\u6001\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u6b63\u5728\u8fd0\u884c\u8fd9\u4e2a\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<pre>var status = git.status{}\n    var filestatus *git.filestatus\n    filestatus = status.file(fullpathtoapp)\n    fmt.printf(\"%v\\n\", filestatus.staging)\n    fmt.printf(\"%v\\n\", filestatus.worktree)<\/pre>\n<p>\u6211\u5f97\u5230\u7684\u53ea\u662f\u6253\u5370\u51fa\u4e24\u4e2a <code>63<\/code> <\/p>\n<pre>63\n63<\/pre>\n<p>\u8fd9\u5728 git \u72b6\u6001\u65b9\u9762\u5bf9\u5e94\u4ec0\u4e48\uff1f<\/p>\n<p>\u6211\u4f3c\u4e4e\u65e0\u6cd5\u4e0e <code>statuscode<\/code> \u7684\u6587\u6863\u5efa\u7acb\u76f4\u63a5\u5173\u7cfb\u3002<\/p>\n<p>\u987a\u4fbf\u8bf4\u4e00\u53e5\uff0c<code>fullpathtoapp<\/code> \u6307\u5411\u7684\u6587\u4ef6\u662f\u5e72\u51c0\u7684\uff0c\u5373\u5b83\u5df2\u88ab\u8ddf\u8e2a\u5e76\u63d0\u4ea4\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u6211\u8ba4\u4e3a\u60a8\u9700\u8981\u5148\u6253\u5f00\u5b58\u50a8\u5e93\u548c\u5de5\u4f5c\u6811<\/p>\n<pre>r, err := git.plainopen(pathtorepo)\n    if err != nil {\n        log.fatal(err)\n    }\n\n    w, err := r.worktree()\n    if err != nil {\n        log.fatal(err)\n    }<\/pre>\n<p>\u4e4b\u540e\u83b7\u53d6\u72b6\u6001<\/p>\n<pre>ws, err := w.status()\n    if err != nil {\n        log.fatal(err)\n    }<\/pre>\n<p>\u8981\u83b7\u53d6\u72b6\u6001\uff0c\u60a8\u53ea\u9700\u8f93\u5165\u5b58\u50a8\u5e93\u4e2d\u7684\u6587\u4ef6\u540d<\/p>\n<pre>fmt.Printf(\"%q\\n\", ws.File(\"filename\").Staging)\n    fmt.Printf(\"%q\\n\", ws.File(\"filename\").Worktree)<\/pre>\n<p>\u6211\u4f3c\u4e4e\u65e0\u6cd5\u4e0e statuscode \u7684\u6587\u6863\u5efa\u7acb\u76f4\u63a5\u5173\u7cfb\u3002<\/p>\n<p>\u8fd4\u56de\u7684\u72b6\u6001\u7801\u662f\u4e00\u4e2a\u5b57\u8282<\/p>\n<p>63 = ?<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300ago-git \u8fd4\u56de\u672a\u77e5\u7684\u72b6\u6001\u7c7b\u578b\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; go-git \u8fd4\u56de\u672a\u77e5\u7684\u72b6\u6001\u7c7b\u578b go-git \u8fd4\u56de\u672a\u77e5\u7684\u72b6\u6001\u7c7b\u578b \u6765\u6e90\uff1astackoverflow 2024-04-25 15:06:35 0\u6d4f\u89c8 \u6536\u85cf \u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898\u662f\u300ago-git \u8fd4\u56de\u672a\u77e5\u7684\u72b6\u6001\u7c7b\u578b\u300b\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8eGolang\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u6b63\u5728\u5c1d\u8bd5\u4f7f\u7528 go-git \u5e93\u83b7\u53d6\u5728 git \u5b58\u50a8\u5e93\u4e2d\u68c0\u67e5\u7684\u6587\u4ef6\u7684\u72b6\u6001\u3002 \u6240\u4ee5\u6211\u6b63\u5728\u8fd0\u884c\u8fd9\u4e2a\u4ee3\u7801\u7247\u6bb5\uff1a var status = git.status{} var filestatus *git.filestatus filestatus = status.file(fullpathtoapp) fmt.printf(&#8220;%v\\n&#8221;, filestatus.staging) fmt.printf(&#8220;%v\\n&#8221;, filestatus.worktree) \u6211\u5f97\u5230\u7684\u53ea\u662f\u6253\u5370\u51fa\u4e24\u4e2a 63 63 63 \u8fd9\u5728 git \u72b6\u6001\u65b9\u9762\u5bf9\u5e94\u4ec0\u4e48\uff1f \u6211\u4f3c\u4e4e\u65e0\u6cd5\u4e0e statuscode \u7684\u6587\u6863\u5efa\u7acb\u76f4\u63a5\u5173\u7cfb\u3002 \u987a\u4fbf\u8bf4\u4e00\u53e5\uff0cfullpathtoapp \u6307\u5411\u7684\u6587\u4ef6\u662f\u5e72\u51c0\u7684\uff0c\u5373\u5b83\u5df2\u88ab\u8ddf\u8e2a\u5e76\u63d0\u4ea4\u3002 \u89e3\u51b3\u65b9\u6848 \u6211\u8ba4\u4e3a\u60a8\u9700\u8981\u5148\u6253\u5f00\u5b58\u50a8\u5e93\u548c\u5de5\u4f5c\u6811 r, err := git.plainopen(pathtorepo) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-42707","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=42707"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42707\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}