{"id":3330,"date":"2025-06-03T14:54:50","date_gmt":"2025-06-03T06:54:50","guid":{"rendered":"https:\/\/www.15zhi.net\/blog\/?p=3330"},"modified":"2025-06-03T15:02:10","modified_gmt":"2025-06-03T07:02:10","slug":"git-%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e9%80%9f%e6%9f%a5%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/www.15zhi.net\/blog\/git-%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e9%80%9f%e6%9f%a5%e8%a1%a8\/","title":{"rendered":"Git \u5e38\u7528\u547d\u4ee4\u901f\u67e5\u8868"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><strong>\u914d\u7f6e\u4fe1\u606f<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u547d\u4ee4<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git config --global user.name \"Your Name\"<\/code><\/td><td>\u8bbe\u7f6e\u5168\u5c40\u7528\u6237\u540d<\/td><\/tr><tr><td><code>git config --global user.email \"email@example.com\"<\/code><\/td><td>\u8bbe\u7f6e\u5168\u5c40\u90ae\u7bb1<\/td><\/tr><tr><td><code>git config --list<\/code><\/td><td>\u67e5\u770b\u5f53\u524d\u914d\u7f6e<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u4ed3\u5e93\u64cd\u4f5c<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u547d\u4ee4<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git init<\/code><\/td><td>\u521d\u59cb\u5316\u65b0\u4ed3\u5e93<\/td><\/tr><tr><td><code>git clone &lt;repo_url&gt;<\/code><\/td><td>\u514b\u9686\u8fdc\u7a0b\u4ed3\u5e93<\/td><\/tr><tr><td><code>git remote add origin &lt;repo_url&gt;<\/code><\/td><td>\u5173\u8054\u8fdc\u7a0b\u4ed3\u5e93<\/td><\/tr><tr><td><code>git remote -v<\/code><\/td><td>\u67e5\u770b\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u63d0\u4ea4\u66f4\u6539<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u547d\u4ee4<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git status<\/code><\/td><td>\u67e5\u770b\u6587\u4ef6\u72b6\u6001<\/td><\/tr><tr><td><code>git add &lt;file&gt;<\/code><\/td><td>\u6dfb\u52a0\u6587\u4ef6\u5230\u6682\u5b58\u533a<\/td><\/tr><tr><td><code>git add .<\/code><\/td><td>\u6dfb\u52a0\u6240\u6709\u4fee\u6539\u5230\u6682\u5b58\u533a<\/td><\/tr><tr><td><code>git commit -m \"Commit message\"<\/code><\/td><td>\u63d0\u4ea4\u66f4\u6539<\/td><\/tr><tr><td><code>git commit --amend<\/code><\/td><td>\u4fee\u6539\u6700\u540e\u4e00\u6b21\u63d0\u4ea4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u5206\u652f\u7ba1\u7406<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u547d\u4ee4<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git branch<\/code><\/td><td>\u67e5\u770b\u672c\u5730\u5206\u652f<\/td><\/tr><tr><td><code>git branch &lt;branch_name&gt;<\/code><\/td><td>\u521b\u5efa\u65b0\u5206\u652f<\/td><\/tr><tr><td><code>git checkout &lt;branch_name&gt;<\/code><\/td><td>\u5207\u6362\u5230\u5206\u652f<\/td><\/tr><tr><td><code>git checkout -b &lt;branch_name&gt;<\/code><\/td><td>\u521b\u5efa\u5e76\u5207\u6362\u5206\u652f<\/td><\/tr><tr><td><code>git merge &lt;branch_name&gt;<\/code><\/td><td>\u5408\u5e76\u5206\u652f\u5230\u5f53\u524d\u5206\u652f<\/td><\/tr><tr><td><code>git branch -d &lt;branch_name&gt;<\/code><\/td><td>\u5220\u9664\u672c\u5730\u5206\u652f<\/td><\/tr><tr><td><code>git push origin --delete &lt;branch_name&gt;<\/code><\/td><td>\u5220\u9664\u8fdc\u7a0b\u5206\u652f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u540c\u6b65\u4e0e\u63a8\u9001<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u547d\u4ee4<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git fetch<\/code><\/td><td>\u4e0b\u8f7d\u8fdc\u7a0b\u53d8\u66f4\uff08\u4e0d\u5408\u5e76\uff09<\/td><\/tr><tr><td><code>git pull<\/code><\/td><td>\u62c9\u53d6\u8fdc\u7a0b\u53d8\u66f4\u5e76\u5408\u5e76\uff08<code>git fetch + git merge<\/code>\uff09<\/td><\/tr><tr><td><code>git pull --rebase<\/code><\/td><td>\u62c9\u53d6\u8fdc\u7a0b\u53d8\u66f4\u5e76\u53d8\u57fa<\/td><\/tr><tr><td><code>git push origin &lt;branch_name&gt;<\/code><\/td><td>\u63a8\u9001\u5206\u652f\u5230\u8fdc\u7a0b<\/td><\/tr><tr><td><code>git push -u origin &lt;branch_name&gt;<\/code><\/td><td>\u63a8\u9001\u5e76\u5173\u8054\u8fdc\u7a0b\u5206\u652f\uff08\u9996\u6b21\u63a8\u9001\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u64a4\u9500\u64cd\u4f5c<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u547d\u4ee4<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git restore &lt;file&gt;<\/code><\/td><td>\u64a4\u9500\u5de5\u4f5c\u533a\u4fee\u6539<\/td><\/tr><tr><td><code>git restore --staged &lt;file&gt;<\/code><\/td><td>\u64a4\u9500\u6682\u5b58\u533a\u4fee\u6539\uff08\u4fdd\u7559\u5de5\u4f5c\u533a\u66f4\u6539\uff09<\/td><\/tr><tr><td><code>git reset HEAD~1<\/code><\/td><td>\u56de\u9000\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\uff08\u4fdd\u7559\u4fee\u6539\uff09<\/td><\/tr><tr><td><code>git reset --hard HEAD~1<\/code><\/td><td>\u5f7b\u5e95\u56de\u9000\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\uff08\u4e22\u5f03\u4fee\u6539\uff09<\/td><\/tr><tr><td><code>git revert &lt;commit_id&gt;<\/code><\/td><td>\u521b\u5efa\u65b0\u63d0\u4ea4\u6765\u64a4\u9500\u6307\u5b9a\u63d0\u4ea4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u67e5\u770b\u4fe1\u606f<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u547d\u4ee4<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git log<\/code><\/td><td>\u67e5\u770b\u63d0\u4ea4\u5386\u53f2<\/td><\/tr><tr><td><code>git log --oneline<\/code><\/td><td>\u7b80\u6d01\u7248\u63d0\u4ea4\u5386\u53f2<\/td><\/tr><tr><td><code>git diff<\/code><\/td><td>\u67e5\u770b\u5de5\u4f5c\u533a\u4e0e\u6682\u5b58\u533a\u7684\u5dee\u5f02<\/td><\/tr><tr><td><code>git diff --staged<\/code><\/td><td>\u67e5\u770b\u6682\u5b58\u533a\u4e0e\u6700\u65b0\u63d0\u4ea4\u7684\u5dee\u5f02<\/td><\/tr><tr><td><code>git show &lt;commit_id&gt;<\/code><\/td><td>\u67e5\u770b\u67d0\u6b21\u63d0\u4ea4\u7684\u8be6\u7ec6\u4fe1\u606f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u50a8\u85cf\u4e0e\u6807\u7b7e<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u547d\u4ee4<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git stash<\/code><\/td><td>\u4e34\u65f6\u50a8\u85cf\u5f53\u524d\u4fee\u6539<\/td><\/tr><tr><td><code>git stash pop<\/code><\/td><td>\u6062\u590d\u50a8\u85cf\u7684\u4fee\u6539<\/td><\/tr><tr><td><code>git tag v1.0<\/code><\/td><td>\u521b\u5efa\u8f7b\u91cf\u6807\u7b7e<\/td><\/tr><tr><td><code>git tag -a v1.0 -m \"Release\"<\/code><\/td><td>\u521b\u5efa\u542b\u6ce8\u91ca\u7684\u6807\u7b7e<\/td><\/tr><tr><td><code>git push origin --tags<\/code><\/td><td>\u63a8\u9001\u6240\u6709\u6807\u7b7e\u5230\u8fdc\u7a0b<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u9ad8\u7ea7\u64cd\u4f5c<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u547d\u4ee4<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>git rebase &lt;branch&gt;<\/code><\/td><td>\u5c06\u5f53\u524d\u5206\u652f\u53d8\u57fa\u5230\u76ee\u6807\u5206\u652f<\/td><\/tr><tr><td><code>git cherry-pick &lt;commit_id&gt;<\/code><\/td><td>\u590d\u5236\u6307\u5b9a\u63d0\u4ea4\u5230\u5f53\u524d\u5206\u652f<\/td><\/tr><tr><td><code>git reflog<\/code><\/td><td>\u67e5\u770b\u6240\u6709\u64cd\u4f5c\u8bb0\u5f55\uff08\u7528\u4e8e\u6062\u590d\u8bef\u5220\u63d0\u4ea4\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u63d0\u793a<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>git &lt;command&gt; -h<\/code> \u67e5\u770b\u547d\u4ee4\u5e2e\u52a9\uff08\u5982 <code>git commit -h<\/code>\uff09<\/li>\n\n\n\n<li>\u8c28\u614e\u4f7f\u7528 <code>git reset --hard<\/code> \u548c <code>git push --force<\/code>\uff08\u4f1a\u8986\u76d6\u5386\u53f2\uff09<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>\u914d\u7f6e\u4fe1\u606f \u547d\u4ee4 \u8bf4\u660e git config &#8211;global user.name &#8220;Your Name&#8221; \u8bbe\u7f6e [&hellip;]<\/p>\n","protected":false},"author":59,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[16],"class_list":["post-3330","post","type-post","status-publish","format-standard","hentry","category-knowledge-base","tag-16"],"_links":{"self":[{"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/posts\/3330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/users\/59"}],"replies":[{"embeddable":true,"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/comments?post=3330"}],"version-history":[{"count":2,"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/posts\/3330\/revisions"}],"predecessor-version":[{"id":3334,"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/posts\/3330\/revisions\/3334"}],"wp:attachment":[{"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/media?parent=3330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/categories?post=3330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.15zhi.net\/blog\/wp-json\/wp\/v2\/tags?post=3330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}