{"id":10020804,"date":"2025-05-29T18:46:44","date_gmt":"2025-05-29T10:46:44","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020804"},"modified":"2025-05-29T18:46:44","modified_gmt":"2025-05-29T10:46:44","slug":"git-%e6%8c%87%e4%bb%a4%e5%a4%a7%e5%85%a8%ef%bc%88%e5%85%a8%e5%b9%b2%e8%b4%a7%e7%89%88%ef%bc%89","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020804","title":{"rendered":"Git \u6307\u4ee4\u5927\u5168\uff08\u5168\u5e72\u8d27\u7248\uff09"},"content":{"rendered":"<h3>\ud83d\udd27 \u57fa\u7840\u64cd\u4f5c<\/h3>\n<pre><code class=\"bash\"># \u521d\u59cb\u5316\u4ed3\u5e93\ngit init\n\n# \u514b\u9686\u8fdc\u7a0b\u4ed3\u5e93\ngit clone &lt;repo_url&gt;\n\n# \u67e5\u770b\u5f53\u524d\u72b6\u6001\ngit status\n\n# \u6dfb\u52a0\u5168\u90e8\u4fee\u6539\u5230\u6682\u5b58\u533a\ngit add .\n\n# \u63d0\u4ea4\u5230\u672c\u5730\u4ed3\u5e93\ngit commit -m &quot;\u63d0\u4ea4\u8bf4\u660e&quot;\n\n# \u67e5\u770b\u63d0\u4ea4\u5386\u53f2\uff08\u7cbe\u7b80\u7248\uff09\ngit log --oneline\n\n# \u67e5\u770b\u6587\u4ef6\u4fee\u6539\u5dee\u5f02\ngit diff<\/code><\/pre>\n<h3>\ud83c\udf3f \u5206\u652f\u7ba1\u7406<\/h3>\n<pre><code class=\"bash\"># \u521b\u5efa\u65b0\u5206\u652f\ngit branch &lt;branch_name&gt;\n\n# \u5207\u6362\u5206\u652f\ngit checkout &lt;branch_name&gt;\n\n# \u521b\u5efa\u5e76\u5207\u6362\u5206\u652f\ngit checkout -b &lt;new_branch&gt;\n\n# \u5408\u5e76\u5206\u652f\u5230\u5f53\u524d\u5206\u652f\ngit merge &lt;branch_name&gt;\n\n# \u5220\u9664\u672c\u5730\u5206\u652f\ngit branch -d &lt;branch_name&gt;\n\n# \u5f3a\u5236\u5220\u9664\u672a\u5408\u5e76\u5206\u652f\ngit branch -D &lt;branch_name&gt;\n\n# \u67e5\u770b\u6240\u6709\u5206\u652f\uff08\u542b\u8fdc\u7a0b\uff09\ngit branch -a<\/code><\/pre>\n<h3>\ud83d\ude80 \u8fdc\u7a0b\u4ed3\u5e93\u64cd\u4f5c<\/h3>\n<pre><code class=\"bash\"># \u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\ngit remote add &lt;remote_name&gt; &lt;repo_url&gt;\n\n# \u63a8\u9001\u672c\u5730\u5206\u652f\u5230\u8fdc\u7a0b\ngit push -u &lt;remote_name&gt; &lt;branch_name&gt;\n\n# \u5f3a\u5236\u63a8\u9001\uff08\u614e\u7528\uff01\uff09\ngit push -f\n\n# \u62c9\u53d6\u8fdc\u7a0b\u66f4\u65b0\ngit pull &lt;remote_name&gt; &lt;branch_name&gt;\n\n# \u83b7\u53d6\u8fdc\u7a0b\u5206\u652f\u4f46\u4e0d\u5408\u5e76\ngit fetch\n\n# \u5220\u9664\u8fdc\u7a0b\u5206\u652f\ngit push &lt;remote_name&gt; --delete &lt;branch_name&gt;<\/code><\/pre>\n<h3>\u23ea \u64a4\u9500\u64cd\u4f5c<\/h3>\n<pre><code class=\"bash\"># \u64a4\u9500\u5de5\u4f5c\u533a\u4fee\u6539\ngit checkout -- &lt;file&gt;\n\n# \u64a4\u9500\u6682\u5b58\u533a\u6587\u4ef6\ngit reset HEAD &lt;file&gt;\n\n# \u4fee\u6539\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\ngit commit --amend\n\n# \u56de\u9000\u5230\u6307\u5b9a\u63d0\u4ea4\uff08\u4fdd\u7559\u4fee\u6539\uff09\ngit reset --soft &lt;commit_id&gt;\n\n# \u5f7b\u5e95\u56de\u9000\u5230\u6307\u5b9a\u63d0\u4ea4\uff08\u614e\u7528\uff01\uff09\ngit reset --hard &lt;commit_id&gt;\n\n# \u6062\u590d\u8bef\u5220\u7684\u6587\u4ef6\ngit checkout &lt;commit_id&gt; -- &lt;file_path&gt;<\/code><\/pre>\n<h3>\ud83d\udd0d \u65e5\u5fd7\u4e0e\u67e5\u8be2<\/h3>\n<pre><code class=\"bash\"># \u56fe\u5f62\u5316\u63d0\u4ea4\u5386\u53f2\ngit log --graph --all\n\n# \u6309\u4f5c\u8005\u641c\u7d22\u63d0\u4ea4\ngit log --author=&quot;name&quot;\n\n# \u641c\u7d22\u63d0\u4ea4\u5185\u5bb9\ngit log -S &quot;keyword&quot;\n\n# \u663e\u793a\u67d0\u6587\u4ef6\u7684\u4fee\u6539\u5386\u53f2\ngit blame &lt;file&gt;<\/code><\/pre>\n<h3>\ud83d\udd17 \u6807\u7b7e\u7ba1\u7406<\/h3>\n<pre><code class=\"bash\"># \u521b\u5efa\u6807\u7b7e\ngit tag &lt;tag_name&gt;\n\n# \u521b\u5efa\u5e26\u6ce8\u91ca\u6807\u7b7e\ngit tag -a v1.0 -m &quot;\u7248\u672c\u8bf4\u660e&quot;\n\n# \u63a8\u9001\u6807\u7b7e\u5230\u8fdc\u7a0b\ngit push --tags\n\n# \u5220\u9664\u672c\u5730\u6807\u7b7e\ngit tag -d &lt;tag_name&gt;\n\n# \u5220\u9664\u8fdc\u7a0b\u6807\u7b7e\ngit push origin :refs\/tags\/&lt;tag_name&gt;<\/code><\/pre>\n<h3>\ud83e\udde9 \u9ad8\u7ea7\u64cd\u4f5c<\/h3>\n<pre><code class=\"bash\"># \u8d2e\u85cf\u5f53\u524d\u4fee\u6539\ngit stash\n\n# \u5e94\u7528\u6700\u8fd1\u8d2e\u85cf\ngit stash pop\n\n# \u4ea4\u4e92\u5f0f\u53d8\u57fa\uff08\u4fee\u6539\u6700\u8fd13\u6b21\u63d0\u4ea4\uff09\ngit rebase -i HEAD~3\n\n# \u4e8c\u5206\u6cd5\u67e5\u627e\u95ee\u9898\u63d0\u4ea4\ngit bisect start\ngit bisect bad         # \u6807\u8bb0\u5f53\u524d\u4e3a\u9519\u8bef\u63d0\u4ea4\ngit bisect good &lt;id&gt;   # \u6807\u8bb0\u5df2\u77e5\u6b63\u5e38\u63d0\u4ea4\n\n# \u6e05\u7406\u672a\u8ddf\u8e2a\u6587\u4ef6\ngit clean -fd<\/code><\/pre>\n<h3>\u2699\ufe0f \u914d\u7f6e\u76f8\u5173<\/h3>\n<pre><code class=\"bash\"># \u5168\u5c40\u7528\u6237\u540d\u914d\u7f6e\ngit config --global user.name &quot;Your Name&quot;\n\n# \u5168\u5c40\u90ae\u7bb1\u914d\u7f6e\ngit config --global user.email &quot;email@example.com&quot;\n\n# \u67e5\u770b\u6240\u6709\u914d\u7f6e\ngit config --list\n\n# \u8bbe\u7f6e\u522b\u540d\uff08\u4f8b\u5982\u7b80\u5316log\uff09\ngit config --global alias.lg &quot;log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset'&quot;<\/code><\/pre>\n<h3>\ud83d\udce6 \u5b50\u6a21\u5757\u7ba1\u7406<\/h3>\n<pre><code class=\"bash\"># \u6dfb\u52a0\u5b50\u6a21\u5757\ngit submodule add &lt;repo_url&gt; &lt;path&gt;\n\n# \u521d\u59cb\u5316\u5b50\u6a21\u5757\ngit submodule init\n\n# \u66f4\u65b0\u5b50\u6a21\u5757\ngit submodule update<\/code><\/pre>\n<h3>\ud83d\udccc \u5b9e\u7528\u6280\u5de7<\/h3>\n<pre><code class=\"bash\"># \u5ffd\u7565\u6587\u4ef6\u6743\u9650\u53d8\u66f4\ngit config core.fileMode false\n\n# \u751f\u6210.gitignore\u6a21\u677f\ncurl https:\/\/gitignore.io\/api\/&lt;\u8bed\u8a00\/\u5de5\u5177&gt;\n\n# \u67e5\u770b\u4ed3\u5e93\u5927\u5c0f\ngit count-objects -vH\n\n# \u514b\u9686\u6307\u5b9a\u5206\u652f\uff08\u6d45\u514b\u9686\uff09\ngit clone --branch &lt;branch_name&gt; --depth 1 &lt;repo_url&gt;<\/code><\/pre>\n<h3>\u6ce8\u610f\u4e8b\u9879\uff1a<\/h3>\n<ol>\n<li>&#8211;force\u64cd\u4f5c\u524d\u52a1\u5fc5\u786e\u8ba4\u5f71\u54cd\u8303\u56f4<\/li>\n<li>\u91cd\u8981\u5206\u652f\uff08\u5982main\/master\uff09\u907f\u514d\u76f4\u63a5\u4fee\u6539<\/li>\n<li>\u63a8\u8350\u4f7f\u7528SSH\u534f\u8bae\u8fdb\u884c\u8fdc\u7a0b\u64cd\u4f5c<\/li>\n<li>\u5b9a\u671f\u6267\u884c git gc \u4f18\u5316\u4ed3\u5e93<\/li>\n<\/ol>\n<h2>dblens\u6570\u636e\u5e93\u5ba2\u6237\u7aef[\u63a8\u8350]<\/h2>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=JcQbGq6duLhX13gBCcnRfQ%3D%3D.fSCOYw9kMqN1vaNvBFDsDinxHiZGs7woXNbpSIT2PcEad%2BR3mUy0Z9fur8l1dmi6Z57Dy6wY%2FwSa1aojargspQ%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/sourceforge.net\/projects\/dblens-for-mysql<\/a><\/p>\n<h6>dblens\u6570\u636e\u5e93\u7ba1\u7406\u5de5\u5177\uff08dblens for mysql\uff09<\/h6>\n<ul>\n<li>\ud83d\udd27 \u53ef\u89c6\u5316\u7d22\u5f15\u4f7f\u7528\u5206\u6790<\/li>\n<li>\ud83d\udcca AI \u7d22\u5f15\u8bbe\u8ba1\u5206\u6790<\/li>\n<li>\ud83d\udca1 \u667a\u80fd\u7d22\u5f15\u4f18\u5316\u5efa\u8bae<\/li>\n<li>\n<p>\ud83d\udcca AI \u5feb\u901f\u8bbe\u8ba1\u8868\u3001\u89c6\u56fe\u3001\u51fd\u6570\u3001\u4e8b\u4ef6\u3001\u5b58\u50a8\u8fc7\u7a0b<\/p>\n<h6>dblens\u6570\u636e\u5e93\u7ba1\u7406\u5de5\u5177<\/h6>\n<\/li>\n<li>\ud83d\udda5 \u53ef\u89c6\u5316\u8bbe\u8ba1\uff1a\u62d6\u62fd\u5f0f\u8868\u7ed3\u6784\u8bbe\u8ba1\uff0cER \u5173\u7cfb\u56fe\u81ea\u52a8\u751f\u6210\uff0c\u964d\u4f4e\u5efa\u6a21\u95e8\u69db\u3002<\/li>\n<li>\u26a1 \u667a\u80fd SQL \u5f00\u53d1\uff1a\u652f\u6301\u8bed\u6cd5\u9ad8\u4eae\u3001\u4ee3\u7801\u8865\u5168\u3001\u6267\u884c\u8ba1\u5212\u5206\u6790\uff0c\u67e5\u8be2\u6548\u7387\u63d0\u5347 50%+\u3002<\/li>\n<li>\u72ec\u7279\u4f18\u52bf \u5168\u4e2d\u6587\u652f\u6301\uff1a\u754c\u9762 \/ \u6587\u6863 \/ \u793e\u533a\u5168\u9762\u672c\u571f\u5316\uff0c\u964d\u4f4e\u5b66\u4e60\u6210\u672c\u3002<\/li>\n<li>\u8de8\u5e73\u53f0\u9002\u914d\uff1aWindows\/macOS\/Linux \u5168\u5e73\u53f0\u517c\u5bb9\u3002<\/li>\n<\/ul>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000046182139\">https:\/\/segmentfault.com\/a\/1190000046182139<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udd27 \u57fa\u7840\u64cd\u4f5c # \u521d\u59cb\u5316\u4ed3\u5e93 git init # \u514b\u9686\u8fdc\u7a0b\u4ed3\u5e93 git clone &lt;repo_url [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020804","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020804"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020804\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}