{"id":10,"date":"2023-01-10T14:13:00","date_gmt":"2023-01-10T06:13:00","guid":{"rendered":"https:\/\/solost.cn\/?p=10"},"modified":"2023-01-10T14:13:43","modified_gmt":"2023-01-10T06:13:43","slug":"10","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=10","title":{"rendered":"git\u547d\u4ee4"},"content":{"rendered":"<p>git\u547d\u4ee4\u5206\u7c7b\u6574\u7406<br \/>\u5168\u5c40\u8bbe\u7f6e<\/p>\n<pre><code>git config --global user.name xxx\uff1a\u8bbe\u7f6e\u5168\u5c40\u7528\u6237\u540d\uff0c\u4fe1\u606f\u8bb0\u5f55\u5728~\/.gitconfig\u6587\u4ef6\u4e2d\ngit config --global user.email xxx@xxx.com\uff1a\u8bbe\u7f6e\u5168\u5c40\u90ae\u7bb1\u5730\u5740\uff0c\u4fe1\u606f\u8bb0\u5f55\u5728~\/.gitconfig\u6587\u4ef6\u4e2d\ngit init\uff1a\u5c06\u5f53\u524d\u76ee\u5f55\u914d\u7f6e\u6210git\u4ed3\u5e93\uff0c\u4fe1\u606f\u8bb0\u5f55\u5728\u9690\u85cf\u7684.git\u6587\u4ef6\u5939\u4e2d<\/code><\/pre>\n<p>\u5e38\u7528\u547d\u4ee4<\/p>\n<pre><code>git add XX \uff1a\u5c06XX\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a\ngit commit -m &quot;\u7ed9\u81ea\u5df1\u770b\u7684\u5907\u6ce8\u4fe1\u606f&quot;\uff1a\u5c06\u6682\u5b58\u533a\u7684\u5185\u5bb9\u63d0\u4ea4\u5230\u5f53\u524d\u5206\u652f\ngit status\uff1a\u67e5\u770b\u4ed3\u5e93\u72b6\u6001\ngit log\uff1a\u67e5\u770b\u5f53\u524d\u5206\u652f\u7684\u6240\u6709\u7248\u672c\ngit push -u (\u7b2c\u4e00\u6b21\u9700\u8981-u\u4ee5\u540e\u4e0d\u9700\u8981) \uff1a\u5c06\u5f53\u524d\u5206\u652f\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\ngit clone git@git.acwing.com:xxx\/XXX.git\uff1a\u5c06\u8fdc\u7a0b\u4ed3\u5e93XXX\u4e0b\u8f7d\u5230\u5f53\u524d\u76ee\u5f55\u4e0b\ngit branch\uff1a\u67e5\u770b\u6240\u6709\u5206\u652f\u548c\u5f53\u524d\u6240\u5904\u5206\u652f<\/code><\/pre>\n<p>\u67e5\u770b\u547d\u4ee4<\/p>\n<pre><code>git diff XX\uff1a\u67e5\u770bXX\u6587\u4ef6\u76f8\u5bf9\u4e8e\u6682\u5b58\u533a\u4fee\u6539\u4e86\u54ea\u4e9b\u5185\u5bb9\ngit status\uff1a\u67e5\u770b\u4ed3\u5e93\u72b6\u6001\ngit log\uff1a\u67e5\u770b\u5f53\u524d\u5206\u652f\u7684\u6240\u6709\u7248\u672c\ngit log --pretty=oneline\uff1a\u7528\u4e00\u884c\u6765\u663e\u793a\ngit reflog\uff1a\u67e5\u770bHEAD\u6307\u9488\u7684\u79fb\u52a8\u5386\u53f2\uff08\u5305\u62ec\u88ab\u56de\u6eda\u7684\u7248\u672c\uff09\ngit branch\uff1a\u67e5\u770b\u6240\u6709\u5206\u652f\u548c\u5f53\u524d\u6240\u5904\u5206\u652f\ngit pull \uff1a\u5c06\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u4e0e\u672c\u5730\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u5408\u5e76<\/code><\/pre>\n<p>\u5220\u9664\u547d\u4ee4<\/p>\n<pre><code>git rm --cached XX\uff1a\u5c06\u6587\u4ef6\u4ece\u4ed3\u5e93\u7d22\u5f15\u76ee\u5f55\u4e2d\u5220\u6389\uff0c\u4e0d\u5e0c\u671b\u7ba1\u7406\u8fd9\u4e2a\u6587\u4ef6\ngit restore --staged xx\uff1a==\u5c06xx\u4ece\u6682\u5b58\u533a\u91cc\u79fb\u9664==\ngit checkout \u2014 XX\u6216git restore XX\uff1a==\u5c06XX\u6587\u4ef6\u5c1a\u672a\u52a0\u5165\u6682\u5b58\u533a\u7684\u4fee\u6539\u5168\u90e8\u64a4\u9500==<\/code><\/pre>\n<p>\u4ee3\u7801\u56de\u6eda<\/p>\n<pre><code>git reset --hard HEAD^ \u6216git reset --hard HEAD~ \uff1a\u5c06\u4ee3\u7801\u5e93\u56de\u6eda\u5230\u4e0a\u4e00\u4e2a\u7248\u672c\ngit reset --hard HEAD^^\uff1a\u5f80\u4e0a\u56de\u6eda\u4e24\u6b21\uff0c\u4ee5\u6b64\u7c7b\u63a8\ngit reset --hard HEAD~100\uff1a\u5f80\u4e0a\u56de\u6eda100\u4e2a\u7248\u672c\ngit reset --hard \u7248\u672c\u53f7\uff1a\u56de\u6eda\u5230\u67d0\u4e00\u7279\u5b9a\u7248\u672c<\/code><\/pre>\n<p>\u8fdc\u7a0b\u4ed3\u5e93<\/p>\n<pre><code>git remote add origin git@git.acwing.com:xxx\/XXX.git\uff1a\u5c06\u672c\u5730\u4ed3\u5e93\u5173\u8054\u5230\u8fdc\u7a0b\u4ed3\u5e93\ngit push -u (\u7b2c\u4e00\u6b21\u9700\u8981-u\u4ee5\u540e\u4e0d\u9700\u8981) \uff1a\u5c06\u5f53\u524d\u5206\u652f\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\ngit push origin branch_name\uff1a\u5c06\u672c\u5730\u7684\u67d0\u4e2a\u5206\u652f\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\ngit clone git@git.acwing.com:xxx\/XXX.git\uff1a\u5c06\u8fdc\u7a0b\u4ed3\u5e93XXX\u4e0b\u8f7d\u5230\u5f53\u524d\u76ee\u5f55\u4e0b\ngit push --set-upstream origin branch_name\uff1a\u8bbe\u7f6e\u672c\u5730\u7684branch_name\u5206\u652f\u5bf9\u5e94\u8fdc\\<\/code><\/pre>\n<p>\u7a0b\u4ed3\u5e93\u7684branch_name\u5206\u652f<\/p>\n<pre><code>git push -d origin branch_name\uff1a\u5220\u9664\u8fdc\u7a0b\u4ed3\u5e93\u7684branch_name\u5206\u652f\ngit checkout -t origin\/branch_name \u5c06\u8fdc\u7a0b\u7684branch_name\u5206\u652f\u62c9\u53d6\u5230\u672c\u5730\ngit pull \uff1a\u5c06\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u4e0e\u672c\u5730\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u5408\u5e76\ngit pull origin branch_name\uff1a\u5c06\u8fdc\u7a0b\u4ed3\u5e93\u7684branch_name\u5206\u652f\u4e0e\u672c\u5730\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u5408\u5e76\ngit branch --set-upstream-to=origin\/branch_name1 branch_name2\uff1a\u5c06\u8fdc\u7a0b\u7684branch_name1\u5206\u652f\u4e0e\u672c\u5730\u7684branch_name2\u5206\u652f\u5bf9\u5e94<\/code><\/pre>\n<p>\u5206\u652f\u547d\u4ee4<\/p>\n<pre><code>git branch branch_name\uff1a\u521b\u5efa\u65b0\u5206\u652f\ngit branch\uff1a\u67e5\u770b\u6240\u6709\u5206\u652f\u548c\u5f53\u524d\u6240\u5904\u5206\u652f\ngit checkout -b branch_name\uff1a\u521b\u5efa\u5e76\u5207\u6362\u5230branch_name\u8fd9\u4e2a\u5206\u652f\ngit checkout branch_name\uff1a\u5207\u6362\u5230branch_name\u8fd9\u4e2a\u5206\u652f\ngit merge branch_name\uff1a\u5c06\u5206\u652fbranch_name\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\u4e0a\ngit branch -d branch_name\uff1a\u5220\u9664\u672c\u5730\u4ed3\u5e93\u7684branch_name\u5206\u652f\ngit push --set-upstream origin branch_name\uff1a\u8bbe\u7f6e\u672c\u5730\u7684branch_name\u5206\u652f\u5bf9\u5e94\u8fdc\u7a0b\u4ed3\u5e93\u7684branch_name\u5206\u652f\ngit push -d origin branch_name\uff1a\u5220\u9664\u8fdc\u7a0b\u4ed3\u5e93\u7684branch_name\u5206\u652f\ngit checkout -t origin\/branch_name \u5c06\u8fdc\u7a0b\u7684branch_name\u5206\u652f\u62c9\u53d6\u5230\u672c\u5730\ngit pull \uff1a\u5c06\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u4e0e\u672c\u5730\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u5408\u5e76\ngit pull origin branch_name\uff1a\u5c06\u8fdc\u7a0b\u4ed3\u5e93\u7684branch_name\u5206\u652f\u4e0e\u672c\u5730\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u5408\u5e76\ngit branch --set-upstream-to=origin\/branch_name1 branch_name2\uff1a\u5c06\u8fdc\u7a0b\u7684branch_name1\u5206\u652f\u4e0e\u672c\u5730\u7684branch_name2\u5206\u652f\u5bf9\u5e94<\/code><\/pre>\n<p>stash\u6682\u5b58<\/p>\n<pre><code>git stash\uff1a\u5c06\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u4e2d\u5c1a\u672a\u63d0\u4ea4\u7684\u4fee\u6539\u5b58\u5165\u6808\u4e2d\ngit stash apply\uff1a\u5c06\u6808\u9876\u5b58\u50a8\u7684\u4fee\u6539\u6062\u590d\u5230\u5f53\u524d\u5206\u652f\uff0c\u4f46\u4e0d\u5220\u9664\u6808\u9876\u5143\u7d20\ngit stash drop\uff1a\u5220\u9664\u6808\u9876\u5b58\u50a8\u7684\u4fee\u6539\ngit stash pop\uff1a\u5c06\u6808\u9876\u5b58\u50a8\u7684\u4fee\u6539\u6062\u590d\u5230\u5f53\u524d\u5206\u652f\uff0c\u540c\u65f6\u5220\u9664\u6808\u9876\u5143\u7d20\ngit stash list\uff1a\u67e5\u770b\u6808\u4e2d\u6240\u6709\u5143\u7d20<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>git\u547d\u4ee4\u5206\u7c7b\u6574\u7406\u5168\u5c40\u8bbe\u7f6e git config --global user.name xxx\uff1a\u8bbe\u7f6e\u5168\u5c40\u7528\u6237\u540d\uff0c\u4fe1\u606f\u8bb0\u5f55\u5728~\/.gitconfig\u6587\u4ef6\u4e2d git config --global user.email xxx@xxx.com\uff1a\u8bbe\u7f6e\u5168\u5c40\u90ae\u7bb1\u5730\u5740\uff0c\u4fe1\u606f\u8bb0\u5f55\u5728~\/.gitconfig\u6587\u4ef6\u4e2d git init\uff1a\u5c06\u5f53\u524d\u76ee\u5f55\u914d\u7f6e\u6210git\u4ed3\u5e93\uff0c\u4fe1\u606f\u8bb0\u5f55\u5728\u9690\u85cf\u7684.git\u6587\u4ef6\u5939\u4e2d \u5e38\u7528\u547d\u4ee4 git add XX \uff1a\u5c06XX\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a git commit -m &quot;\u7ed9\u81ea\u5df1\u770b\u7684\u5907\u6ce8\u4fe1\u606f&quot;\uff1a\u5c06\u6682\u5b58\u533a\u7684\u5185\u5bb9\u63d0\u4ea4\u5230\u5f53\u524d\u5206\u652f git status\uff1a\u67e5\u770b\u4ed3\u5e93\u72b6\u6001 git log\uff1a\u67e5\u770b\u5f53\u524d\u5206\u652f\u7684\u6240\u6709\u7248\u672c git push -u (\u7b2c\u4e00\u6b21\u9700\u8981-u\u4ee5\u540e\u4e0d\u9700\u8981) \uff1a\u5c06\u5f53\u524d\u5206\u652f\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93 git clone git@git.acwing.com:xxx\/XXX.git\uff1a\u5c06\u8fdc\u7a0b\u4ed3\u5e93XXX\u4e0b\u8f7d\u5230\u5f53\u524d\u76ee\u5f55\u4e0b git branch\uff1a\u67e5\u770b\u6240\u6709\u5206\u652f\u548c\u5f53\u524d\u6240\u5904\u5206\u652f \u67e5\u770b\u547d\u4ee4 git diff XX\uff1a\u67e5\u770bXX\u6587\u4ef6\u76f8\u5bf9\u4e8e\u6682\u5b58\u533a\u4fee\u6539\u4e86\u54ea\u4e9b\u5185\u5bb9 git status\uff1a\u67e5\u770b\u4ed3\u5e93\u72b6\u6001 git log\uff1a\u67e5\u770b\u5f53\u524d\u5206\u652f\u7684\u6240\u6709\u7248\u672c git log --pretty=oneline\uff1a\u7528\u4e00\u884c\u6765\u663e\u793a git reflog\uff1a\u67e5\u770bHEAD\u6307\u9488\u7684\u79fb\u52a8\u5386\u53f2\uff08\u5305\u62ec\u88ab\u56de\u6eda\u7684\u7248\u672c\uff09 git branch\uff1a\u67e5\u770b\u6240\u6709\u5206\u652f\u548c\u5f53\u524d\u6240\u5904\u5206\u652f git pull \uff1a\u5c06\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u4e0e\u672c\u5730\u4ed3\u5e93\u7684\u5f53\u524d\u5206\u652f\u5408\u5e76 \u5220\u9664\u547d\u4ee4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/10\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}