{"id":1002,"date":"2021-05-08T15:54:00","date_gmt":"2021-05-08T07:54:00","guid":{"rendered":"https:\/\/beijian99.top\/?p=1002"},"modified":"2025-05-08T16:37:57","modified_gmt":"2025-05-08T08:37:57","slug":"git%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/beijian99.top\/?p=1002","title":{"rendered":"Git\u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/beijian99.top\/wp-content\/uploads\/2025\/05\/image-1.png\" alt=\"\" class=\"wp-image-1004\"\/><\/figure>\n\n\n\n<p>\u4e00\u3001Git\u57fa\u7840\u914d\u7f6e<\/p>\n\n\n\n<p>\u5728\u5f00\u59cb\u4f7f\u7528Git\u4e4b\u524d\uff0c\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u57fa\u7840\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u8bbe\u7f6e\u5168\u5c40\u7528\u6237\u540d<br>git config --global user.name \"Your Name\"<br><br># \u8bbe\u7f6e\u5168\u5c40\u90ae\u7bb1<br>git config --global user.email \"your.email@example.com\"<br><br># \u67e5\u770b\u6240\u6709\u914d\u7f6e<br>git config --list<br><br># \u8bbe\u7f6e\u9ed8\u8ba4\u7f16\u8f91\u5668\u4e3aVS Code<br>git config --global core.editor \"code --wait\"<\/code><\/pre>\n\n\n\n<p>\u4e8c\u3001\u4ed3\u5e93\u521b\u5efa\u4e0e\u514b\u9686<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u521d\u59cb\u5316\u65b0\u4ed3\u5e93<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u5728\u5f53\u524d\u76ee\u5f55\u521d\u59cb\u5316\u65b0\u4ed3\u5e93<br>git init<br><br># \u521d\u59cb\u5316\u5e76\u6307\u5b9a\u76ee\u5f55\u540d<br>git init &lt;directory-name&gt;<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u514b\u9686\u73b0\u6709\u4ed3\u5e93<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u514b\u9686\u8fdc\u7a0b\u4ed3\u5e93<br>git clone &lt;repository-url&gt;<br><br># \u514b\u9686\u6307\u5b9a\u5206\u652f<br>git clone -b &lt;branch-name&gt; &lt;repository-url&gt;<br><br># \u514b\u9686\u5e76\u6307\u5b9a\u672c\u5730\u76ee\u5f55\u540d<br>git clone &lt;repository-url&gt; &lt;directory-name&gt;<\/code><\/pre>\n\n\n\n<p>\u4e09\u3001\u57fa\u672c\u5de5\u4f5c\u6d41\u7a0b<\/p>\n\n\n\n<p>Git\u7684\u57fa\u672c\u5de5\u4f5c\u6d41\u7a0b\u5305\u62ec\uff1a\u4fee\u6539\u6587\u4ef6\u3001\u6682\u5b58\u66f4\u6539\u3001\u63d0\u4ea4\u66f4\u6539\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u67e5\u770b\u4ed3\u5e93\u72b6\u6001<br>git status<br><br># \u6dfb\u52a0\u6587\u4ef6\u5230\u6682\u5b58\u533a<br>git add &lt;file-name&gt;<br><br># \u6dfb\u52a0\u6240\u6709\u66f4\u6539\u6587\u4ef6<br>git add .<br><br># \u63d0\u4ea4\u6682\u5b58\u533a\u7684\u66f4\u6539<br>git commit -m \"\u63d0\u4ea4\u4fe1\u606f\"<br><br># \u4e00\u6b21\u6027\u6dfb\u52a0\u5e76\u63d0\u4ea4\u6240\u6709\u66f4\u6539\uff08\u4e0d\u5305\u62ec\u672a\u8ddf\u8e2a\u6587\u4ef6\uff09<br>git commit -a -m \"\u63d0\u4ea4\u4fe1\u606f\"<\/code><\/pre>\n\n\n\n<p>\u56db\u3001\u5206\u652f\u7ba1\u7406<\/p>\n\n\n\n<p>\u5206\u652f\u662fGit\u7684\u6838\u5fc3\u529f\u80fd\u4e4b\u4e00\uff0c\u5141\u8bb8\u591a\u7ebf\u5f00\u53d1\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u67e5\u770b\u6240\u6709\u5206\u652f<br>git branch<br><br># \u521b\u5efa\u65b0\u5206\u652f<br>git branch &lt;branch-name&gt;<br><br># \u5207\u6362\u5206\u652f<br>git checkout &lt;branch-name&gt;<br><br># \u521b\u5efa\u5e76\u5207\u6362\u5230\u65b0\u5206\u652f<br>git checkout -b &lt;branch-name&gt;<br><br># \u5220\u9664\u5206\u652f\uff08\u5df2\u5408\u5e76\uff09<br>git branch -d &lt;branch-name&gt;<br><br># \u5f3a\u5236\u5220\u9664\u5206\u652f\uff08\u672a\u5408\u5e76\uff09<br>git branch -D &lt;branch-name&gt;<br><br># \u91cd\u547d\u540d\u5f53\u524d\u5206\u652f<br>git branch -m &lt;new-name&gt;<\/code><\/pre>\n\n\n\n<p>\u4e94\u3001\u8fdc\u7a0b\u4ed3\u5e93\u64cd\u4f5c<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u67e5\u770b\u8fdc\u7a0b\u4ed3\u5e93<br>git remote -v<br><br># \u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93<br>git remote add &lt;remote-name&gt; &lt;repository-url&gt;<br><br># \u91cd\u547d\u540d\u8fdc\u7a0b\u4ed3\u5e93<br>git remote rename &lt;old-name&gt; &lt;new-name&gt;<br><br># \u79fb\u9664\u8fdc\u7a0b\u4ed3\u5e93<br>git remote remove &lt;remote-name&gt;<br><br># \u83b7\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u66f4\u65b0\u4f46\u4e0d\u5408\u5e76<br>git fetch &lt;remote-name&gt;<br><br># \u62c9\u53d6\u8fdc\u7a0b\u5206\u652f\u5e76\u5408\u5e76<br>git pull &lt;remote-name&gt; &lt;branch-name&gt;<br><br># \u63a8\u9001\u672c\u5730\u5206\u652f\u5230\u8fdc\u7a0b<br>git push &lt;remote-name&gt; &lt;branch-name&gt;<br><br># \u63a8\u9001\u5e76\u8bbe\u7f6e\u4e0a\u6e38\u5206\u652f<br>git push -u &lt;remote-name&gt; &lt;branch-name&gt;<\/code><\/pre>\n\n\n\n<p>\u516d\u3001\u64a4\u9500\u4e0e\u56de\u9000<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u64a4\u9500\u5de5\u4f5c\u533a\u4fee\u6539\uff08\u672a\u6682\u5b58\uff09<br>git checkout -- &lt;file-name&gt;<br><br># \u64a4\u9500\u6682\u5b58\u533a\u7684\u4fee\u6539\uff08\u5df2add\u672acommit\uff09<br>git reset HEAD &lt;file-name&gt;<br><br># \u4fee\u6539\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\uff08\u672a\u63a8\u9001\uff09<br>git commit --amend<br><br># \u56de\u9000\u5230\u6307\u5b9a\u63d0\u4ea4\uff08\u4fdd\u7559\u66f4\u6539\uff09<br>git reset &lt;commit-hash&gt;<br><br># \u56de\u9000\u5230\u6307\u5b9a\u63d0\u4ea4\uff08\u4e22\u5f03\u66f4\u6539\uff09<br>git reset --hard &lt;commit-hash&gt;<br><br># \u56de\u9000\u8fdc\u7a0b\u5206\u652f\uff08\u8c28\u614e\u4f7f\u7528\uff09<br>git push -f &lt;remote-name&gt; &lt;branch-name&gt;<\/code><\/pre>\n\n\n\n<p>\u4e03\u3001\u65e5\u5fd7\u4e0e\u5386\u53f2<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u67e5\u770b\u63d0\u4ea4\u5386\u53f2<br>git log<br><br># \u7b80\u6d01\u663e\u793a\u63d0\u4ea4\u5386\u53f2<br>git log --oneline<br><br># \u663e\u793a\u5206\u652f\u56fe<br>git log --graph --oneline --all<br><br># \u67e5\u770b\u6587\u4ef6\u4fee\u6539\u5386\u53f2<br>git log -p &lt;file-name&gt;<br><br># \u67e5\u770b\u67d0\u4eba\u7684\u63d0\u4ea4<br>git log --author=\"name\"<br><br># \u641c\u7d22\u63d0\u4ea4\u4fe1\u606f<br>git log --grep=\"keyword\"<br><br># \u663e\u793a\u66f4\u6539\u7edf\u8ba1<br>git log --stat<\/code><\/pre>\n\n\n\n<p>\u516b\u3001\u6807\u7b7e\u7ba1\u7406<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u5217\u51fa\u6240\u6709\u6807\u7b7e<br>git tag<br><br># \u521b\u5efa\u8f7b\u91cf\u6807\u7b7e<br>git tag &lt;tag-name&gt;<br><br># \u521b\u5efa\u542b\u6ce8\u91ca\u7684\u6807\u7b7e<br>git tag -a &lt;tag-name&gt; -m \"message\"<br><br># \u63a8\u9001\u6807\u7b7e\u5230\u8fdc\u7a0b<br>git push &lt;remote-name&gt; &lt;tag-name&gt;<br><br># \u63a8\u9001\u6240\u6709\u6807\u7b7e<br>git push &lt;remote-name&gt; --tags<br><br># \u5220\u9664\u672c\u5730\u6807\u7b7e<br>git tag -d &lt;tag-name&gt;<br><br># \u5220\u9664\u8fdc\u7a0b\u6807\u7b7e<br>git push &lt;remote-name&gt; :refs\/tags\/&lt;tag-name&gt;<\/code><\/pre>\n\n\n\n<p>\u4e5d\u3001\u9ad8\u7ea7\u64cd\u4f5c<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u50a8\u85cf\u66f4\u6539<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u50a8\u85cf\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55<br>git stash<br><br># \u67e5\u770b\u50a8\u85cf\u5217\u8868<br>git stash list<br><br># \u6062\u590d\u6700\u8fd1\u50a8\u85cf<br>git stash pop<br><br># \u6062\u590d\u6307\u5b9a\u50a8\u85cf<br>git stash apply stash@{n}<br><br># \u5220\u9664\u50a8\u85cf<br>git stash drop stash@{n}<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u53d8\u57fa\u64cd\u4f5c<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u53d8\u57fa\u5f53\u524d\u5206\u652f\u5230\u76ee\u6807\u5206\u652f<br>git rebase &lt;target-branch&gt;<br><br># \u4ea4\u4e92\u5f0f\u53d8\u57fa<br>git rebase -i &lt;commit-hash&gt;<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>\u5b50\u6a21\u5757<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># \u6dfb\u52a0\u5b50\u6a21\u5757<br>git submodule add &lt;repository-url&gt; &lt;path&gt;<br><br># \u521d\u59cb\u5316\u5b50\u6a21\u5757<br>git submodule init<br><br># \u66f4\u65b0\u5b50\u6a21\u5757<br>git submodule update<\/code><\/pre>\n\n\n\n<p>\u5341\u3001\u5dee\u5f02\u6bd4\u8f83<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ngit diff                # \u5de5\u4f5c\u533a\u4e0e\u6682\u5b58\u533a\u5dee\u5f02\ngit diff --cached       # \u6682\u5b58\u533a\u4e0e\u6700\u65b0\u63d0\u4ea4\u5dee\u5f02\ngit diff HEAD           # \u5de5\u4f5c\u533a\u4e0e\u6700\u65b0\u63d0\u4ea4\u5dee\u5f02\ngit diff &lt;commit1&gt; &lt;commit2&gt; # \u6bd4\u8f83\u4e24\u4e2a\u63d0\u4ea4\u4e4b\u95f4\u7684\u5dee\u5f02\u3002\u53ef\u4ee5\u4f7f\u7528\u63d0\u4ea4\u54c8\u5e0c\u3001\u5206\u652f\u540d\u6216\u6807\u7b7e\u540d\u3002\ngit diff &lt;commit1&gt; &lt;commit2&gt; -- &lt;file-path&gt;  # \u6bd4\u8f83\u7279\u5b9a\u6587\u4ef6\u7684\u5dee\u5f02\n\n# \u67e5\u770b\u5f53\u524d\u5206\u652f\u6bd4master\u591a\u4e86\u54ea\u4e9b\u4fee\u6539\ngit diff master..HEAD\n# \u67e5\u770bfeature\u5206\u652f\u6bd4develop\u5206\u652f\u5c11\u4e86\u54ea\u4e9b\u5185\u5bb9\ngit diff develop..feature\n#\u663e\u793a\u53d8\u66f4\u7684\u7edf\u8ba1\u4fe1\u606f\uff0c\u5305\u62ec\u54ea\u4e9b\u6587\u4ef6\u88ab\u4fee\u6539\u4ee5\u53ca\u589e\u5220\u884c\u6570\u3002\ngit diff --stat\n<\/pre><\/div>\n\n\n<p>\u5341\u4e00\u3001\u7cbe\u9009\u63d0\u4ea4 cherry-pick<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# \u5207\u6362\u5230\u76ee\u6807\u5206\u652f\ngit checkout main\n\n# \u7cbe\u9009\u5355\u4e2a\u63d0\u4ea4\ngit cherry-pick &lt;commit-hash&gt;\n\n# \u7cbe\u9009\u591a\u4e2a\u63d0\u4ea4\uff08\u6309\u987a\u5e8f\u5e94\u7528\uff09\ngit cherry-pick &lt;commit1&gt; &lt;commit2&gt;\n# \u7cbe\u9009\u4f46\u4e0d\u81ea\u52a8\u63d0\u4ea4\uff08\u5141\u8bb8\u4fee\u6539\uff09\ngit cherry-pick -n &lt;commit-hash&gt;\n\n# \u7cbe\u9009\u5e76\u7f16\u8f91\u63d0\u4ea4\u4fe1\u606f\ngit cherry-pick -e &lt;commit-hash&gt;\n\n# \u7cbe\u9009\u5e76\u7b7e\u540d\u63d0\u4ea4\ngit cherry-pick -s &lt;commit-hash&gt;\n\n# \u7cbe\u9009\u4e00\u4e2a\u8303\u56f4\u5185\u7684\u63d0\u4ea4\uff08\u4e0d\u5305\u62ecstart\uff09\ngit cherry-pick &lt;start-commit&gt;..&lt;end-commit&gt;\n\n# \u7cbe\u9009\u4e00\u4e2a\u8303\u56f4\u5185\u7684\u63d0\u4ea4\uff08\u5305\u62ecstart\uff09\ngit cherry-pick &lt;start-commit&gt;^..&lt;end-commit&gt;\n\n<\/pre><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001Git\u57fa\u7840\u914d\u7f6e \u5728\u5f00\u59cb\u4f7f\u7528Git\u4e4b\u524d\uff0c\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u57fa\u7840\u914d\u7f6e\uff1a # \u8bbe\u7f6e\u5168\u5c40\u7528\u6237\u540dgit config &#8212; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1006,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[131],"tags":[149],"class_list":["post-1002","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-131","tag-git"],"_links":{"self":[{"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/posts\/1002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/beijian99.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1002"}],"version-history":[{"count":4,"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/posts\/1002\/revisions"}],"predecessor-version":[{"id":1011,"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/posts\/1002\/revisions\/1011"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/media\/1006"}],"wp:attachment":[{"href":"https:\/\/beijian99.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/beijian99.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beijian99.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}