{"id":1123,"date":"2017-07-04T18:55:55","date_gmt":"2017-07-04T10:55:55","guid":{"rendered":"http:\/\/feizhaojun.com\/?p=1123"},"modified":"2020-03-05T17:56:26","modified_gmt":"2020-03-05T09:56:26","slug":"git%e5%9f%ba%e6%9c%ac%e6%93%8d%e4%bd%9c%e6%89%8b%e5%86%8c","status":"publish","type":"post","link":"https:\/\/feizhaojun.com\/?p=1123","title":{"rendered":"Git\u57fa\u672c\u64cd\u4f5c\u624b\u518c"},"content":{"rendered":"<h5>\u751f\u6210\u3001\u914d\u7f6e SSH key<\/h5>\n<p>\u5148\u4f7f\u7528 ssh-keygen \u547d\u4ee4\u751f\u6210\u4e00\u4e2a key\uff0c\u8bb0\u5f97\u5e26\u4e0a\u4f60\u5728\u76f8\u5e94 git \u670d\u52a1\u5668\u7684\u7528\u6237\u540d\uff0c\u7136\u540e\u67e5\u770b .pub \u7ed3\u5c3e\u7684\u6587\u4ef6\uff0c\u590d\u5236\u6587\u4ef6\u4e2d\u7684\u6587\u672c\u586b\u5199\u5230 git \u670d\u52a1\u76f8\u5e94\u7684\u8bbe\u7f6e\uff08\u4e00\u822c\u5728\u8bbe\u7f6e\u2192SSH-KEY\uff09\u91cc\u9762\u3002<\/p>\n<pre><code class=\"language-sh\"># \u751f\u6210\uff08POSIX\u7cfb\u7edf\uff09\nssh-keygen -t rsa -C \"fzjlovemy@163.com\"\n# \u67e5\u770b\ncat ~\/.ssh\/id_rsa.pub\n\n# \u751f\u6210\uff08Windows\u7cfb\u7edf\uff09\nssh-keygen -t rsa -C \"feizhaojun@xdf.cn\"\n# \u67e5\u770b\ncat \/c\/Users\/Mukti\/.ssh\/id_rsa.pub\n\n# \u6307\u5b9a\u5b58\u50a8\u8def\u5f84\nssh-keygen -t rsa -C 'fzjlovemy@163.com' -f ~\/.ssh\/id_rsa_gitee\n<\/code><\/pre>\n<p>\u5728 git \u670d\u52a1\u7684 SSH-KEY \u4e2d\u586b\u597d\u4e4b\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u6d4b\u8bd5\u662f\u5426\u914d\u7f6e\u6210\u529f\uff1a<\/p>\n<pre><code># \u6d4b\u8bd5\nssh -T git@gitee.com\n<\/code><\/pre>\n<h5>\u540c\u8bbe\u5907\u8bbf\u95ee\u591a\u4e2agit\u5e10\u6237\u914d\u7f6eSSH<\/h5>\n<p>\u5728 ~\/.ssh \u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2aconfig\u6587\u4ef6\uff0c\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff08\u5176\u4e2dHost\u548cHostName\u586b\u5199git\u670d\u52a1\u5668\u7684\u57df\u540d\uff0cIdentityFile\u6307\u5b9a\u79c1\u94a5\u7684\u8def\u5f84\uff09<\/p>\n<pre><code># gitee\nHost gitee.com\nHostName gitee.com\nPreferredAuthentications publickey\nIdentityFile ~\/.ssh\/id_rsa_gitee\n\n# github\nHost github.com\nHostName github.com\nPreferredAuthentications publickey\nIdentityFile ~\/.ssh\/id_rsa_github\n\n# 66xue\nHost gitlab.66xue.com\nHostName gitlab.66xue.com\nPreferredAuthentications publickey\nIdentityFile ~\/.ssh\/id_rsa\n<\/code><\/pre>\n<p>\u7528ssh\u547d\u4ee4\u5206\u522b\u6d4b\u8bd5<\/p>\n<pre><code>$ ssh -T git@gitee.com\n$ ssh -T git@github.com\n<\/code><\/pre>\n<p>\u7528\u6237\u64cd\u4f5c<\/p>\n<pre><code>git config user.name  # \u67e5\u770b\u7528\u6237\u540d\ngit config --global user.name  # \u67e5\u770b\u5168\u5c40\u7528\u6237\u540d\ngit config user.name \"Mukti\"  # \u8bbe\u7f6e\u7528\u6237\u540d\ngit config credential.helper store  # \u8bb0\u4f4f\u5bc6\u7801\n<\/code><\/pre>\n<p>\u57fa\u672c\u64cd\u4f5c<\/p>\n<pre><code class=\"language-sh\">git init    # \u521d\u59cb\u5316\u4e00\u4e2a git repo\ngit status # \u67e5\u770b\u72b6\u6001\ngit log # \u67e5\u770b\u5386\u53f2\u8bb0\u5f55\ngit log --pretty=oneline # \u5355\u884c\u7b80\u8981\u663e\u793a\u4e00\u6b21\u8bb0\u5f55\ngit reflog # \u53ef\u4ee5\u67e5\u770b\u6240\u6709\u5206\u652f\u7684\u6240\u6709\u64cd\u4f5c\u8bb0\u5f55\uff0c\u5305\u62ec\u5df2\u7ecf\u88ab\u5220\u9664\u7684 commit \u8bb0\u5f55\u548c reset \u7684\u64cd\u4f5c\ngit add &lt;file&gt; # \u5c06\u4e00\u4e2a\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a stage\ngit commit -m -a # \u63d0\u4ea4\uff0c\u53c2\u6570\u201c-a\u201d\u5305\u62ec\u4e86\u201cgit add\u201d\ngit rm &lt;\/file&gt;&lt;file&gt; # git add \u76f8\u53cd\ngit rm --cached &lt;\/file&gt;&lt;file&gt; # unstage\uff0c\u4f46\u662f\u4fdd\u7559\u7269\u7406\u6587\u4ef6\ngit diff # \u67e5\u770b\u6587\u4ef6\u53d8\u66f4\uff08\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u5bf9\u6bd4\uff09\ngit diff --cached # git add \u4e4b\u540e\u67e5\u770b\u4e0e\u4e0a\u4e00\u7248\u672c\u7684\u533a\u522b\uff08\u6682\u5b58\u533a\u548c\u5df2\u63d0\u4ea4\u5bf9\u6bd4\uff09\n<\/code><\/pre>\n<p>\u6094\u6539<\/p>\n<pre><code class=\"language-sh\">git checkout -- &lt;filename&gt; # \u64a4\u9500\u672a\u6682\u5b58\u7684\u6587\u4ef6\uff08\u5de5\u4f5c\u533a\uff09\u7684\u4fee\u6539\ngit reset --hard HEAD^  # HEAD\u6307\u9488\u4e0a\u79fb\u4e00\u4e2a\uff0c\u56de\u9000\u5230\u4e0a\u4e00\u4e2a\u7248\u672c\u3002^^\u56de\u9000\u524d2\u4e2a\u7248\u672c\ngit reset --hard HEAD~100  # \u56de\u9000\u524d100\u4e2a\u7248\u672c\ngit reset --hard &lt;commitid&gt; # \u56de\u9000\u5230\u67d0\u4e2a\u7248\u672c\u53f7\ngit reset --hard origin\/master # \u56de\u9000\u5230\u8fdc\u7aef\u4ed3\u5e93\n<\/code><\/pre>\n<p>\u8fdc\u7a0b\u4ed3\u5e93<\/p>\n<pre><code class=\"language-sh\">git clone &lt;url&gt; # \u514b\u9686\uff0c\u4f1a\u81ea\u52a8\u5173\u8054\u8fdc\u7a0b\u5206\u652f\uff0cpull\u6216push\u65e0\u9700\u6307\u5b9a\u8fdc\u7a0b\u5206\u652f\ngit remote # \u67e5\u770b\u5173\u8054\u7684\u8fdc\u7a0b\u4ed3\u5e93\ngit remote -v # \u67e5\u770b\u5173\u8054\u7684\u8fdc\u7a0b\u4ed3\u5e93\u7684\u8be6\u7ec6\u4fe1\u606f\ngit remote add &lt;origin&gt; git@gitee.com:mukti\/mukti-test.git # \u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5173\u8054\ngit remote remove origin # \u5220\u9664\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5173\u8054\ngit remote set-url origin &lt;newurl&gt; # \u4fee\u6539\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5173\u8054\uff0c\u4e5f\u53ef\u4ee5\u5220\u9664\u518d\u6dfb\u52a0\uff0c\u4e5f\u53ef\u4ee5\u4fee\u6539.git\u76ee\u5f55\u7684config\u6587\u4ef6\ngit branch --set-upstream-to=origin\/master master # \u5173\u8054\u672c\u5730\u4e0e\u8fdc\u7a0b\u7684\u5206\u652f\uff0c\u6bcf\u6b21pull\u548cpush\u4e0d\u9700\u8981\u6307\u5b9a\u5206\u652f\n\/\/ git pull --allow-unrelated-histories # \u8fdc\u7a0b\u5e93\u548c\u672c\u5730\u5e93\u672c\u6765\u662f\u72ec\u7acb\u7684\u5e93\uff0c\u9700\u8981\u5408\u5e76\u4e24\u4e2a\u5e93\ngit pull &lt;origin&gt; &lt;branchname&gt;\ngit push # \u63a8\u9001\u5f53\u524d\u5206\u652f\u5230\u9ed8\u8ba4\u8fdc\u7a0b\u5e93\u7684\u5bf9\u5e94\u5206\u652f\uff0c\u5982\u679c\u8fdc\u7a0b\u4e0d\u5b58\u5728\u5bf9\u5e94\u5206\u652f\u5219\u62a5\u9519\ngit push &lt;origin&gt; # \u63a8\u9001\u5f53\u524d\u5206\u652f\u5230\u8fdc\u7a0b\u5e93&lt;\/origin&gt;&lt;origin&gt;\u7684\u5bf9\u5e94\u5206\u652f\ngit push &lt;\/origin&gt;&lt;origin&gt; &lt;branchname&gt; # \u5c06\u672c\u5730&lt;\/branchname&gt;&lt;branchname&gt;\u63a8\u9001\u5230\u8fdc\u7a0b&lt;\/branchname&gt;&lt;branchname&gt;\u5206\u652f\uff0c\u5982\u679c\u672c\u5730\u4e0d\u5b58\u5728&lt;\/branchname&gt;&lt;branchname&gt;\u5206\u652f\u5219\u62a5\u9519\ngit push -u origin master # \u53c2\u6570\u201c-u\u201d\u5c06\u201corigin master\u201d\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u7684\u8fdc\u7a0b\u4ed3\u5e93\u548c\u5206\u652f\uff0c\u4ee5\u540e\u4e0d\u9700\u8981\u518d\u6307\u5b9a\n<\/code><\/pre>\n<p>\u5206\u652f<\/p>\n<pre><code class=\"language-sh\">git branch # \u5217\u51fa repo \u4e2d\u6240\u6709\u5206\u652f\ngit branch -a # \u5217\u51fa\u672c\u5730\u548c\u8fdc\u7a0b\u6240\u6709\u5206\u652f\ngit branch &lt;\/branchname&gt;&lt;branchname&gt; # \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\ngit branch &lt;newbranchname&gt; &lt;branchname&gt; # \u57fa\u4e8e&lt;\/branchname&gt;&lt;branchname&gt;\u5206\u652f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\ngit brach &lt;\/branchname&gt;&lt;branchname&gt; &lt;commitid&gt; # \u57fa\u4e8e\u5f53\u524d\u5206\u652f\u7684\u63d0\u4ea4\u7248\u672c\u53f7\u521b\u5efa\u65b0\u7684\u5206\u652f\ngit branch -d &lt;branchname&gt; # \u5220\u9664\u5206\u652f -D \u5927\u5199\u662f\u5f3a\u5236\u5220\u9664\uff0c\u4e0d\u51fa\u73b0\u5408\u5e76\u63d0\u793a\n\n# \u5220\u9664\u8fdc\u7a0b\u5206\u652f\ngit push &lt;origin&gt; :&lt;branchname&gt;\ngit push -d &lt;origin&gt; &lt;branchname&gt;\ngit push --delete &lt;origin&gt; &lt;branchname&gt;\n\n# \u5207\u6362\u5230\u5206\u652f\ngit checkout &lt;\/branchname&gt;&lt;branchname&gt;\ngit checkout -b &lt;\/branchname&gt;&lt;branchname&gt; # \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\uff0c\u5e76\u5207\u6362\u5230\u65b0\u5206\u652f \u76f8\u5f53\u4e8e git branch [name] + git checkout [name]\n\ngit checkout \u2013b &lt;newbranchname&gt; &lt;branchname&gt; # \u57fa\u4e8e&lt;\/branchname&gt;&lt;branchname&gt;\u5206\u652f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\ngit checkout \u2013b &lt;newbranchname&gt; &lt;origin&gt;\/&lt;branchname&gt; # \u57fa\u4e8e\u8fdc\u7a0b\u7684\u67d0\u4e2a\u5206\u652f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\uff0c\u4ece\u8fdc\u7a0b\u5206\u652f\u62c9\u53bb\u7684\u65b0\u5206\u652fpush\u7684\u65f6\u5019\u4f1a\u5728\u8fdc\u7a0b\u67e5\u627e\u540c\u540d\u5206\u652f\uff0c\u5982\u679c\u6ca1\u6709\u4f1a\u63d0\u793a\uff0c\u4e0d\u4f1a\u76f4\u63a5push\u5230\u6e90\u5206\u652f\u3002\u5982\u679c\u8fdc\u7a0b\u5206\u652f\u662f\u65b0\u5206\u652f\uff0c\u9700\u8981\u5148 pull\n<\/code><\/pre>\n<p>\u5408\u5e76\u5206\u652f\uff1f<\/p>\n<pre><code class=\"language-sh\">git merge &lt;\/branchname&gt;&lt;branchname&gt; # \u5408\u5e76&lt;\/branchname&gt;&lt;branchname&gt;\u5230\u5f53\u524d\u5206\u652f\ngit merge --abort # \u653e\u5f03\u5e76\u5165\u5206\u652f\uff08\u975e\u5f53\u524d\uff09\u7684\u4fee\u6539\ngit merge \u2013no-ff -m \"&lt;comments&gt;\" &lt;branchname&gt; # \u4e0d\u4f7f\u7528Fast forward\u6a21\u5f0f\u5408\u5e76\u5206\u652f\uff0c\u5408\u5e76\u7684\u5206\u652f\u5220\u9664\u540e\uff0c\u53ef\u4ee5\u4fdd\u7559\u63d0\u4ea4\u8bb0\u5f55\u3002\ngit merge &lt;brancha&gt; &lt;branchb&gt; # \u5c06&lt;brancha&gt;\u5206\u652f\u5408\u5e76\u5230&lt;branchb&gt;\u5206\u652f\n\ngit rebase &lt;branchname&gt;\n<\/code><\/pre>\n<p>\u6682\u65f6\u9690\u85cf\u5de5\u4f5c<\/p>\n<pre><code class=\"language-sh\">git stash # \u9690\u85cf\u5f53\u524d\u5de5\u4f5c\ngit stash list # \u67e5\u770b\u6240\u4ee5\u88ab\u9690\u85cf\u7684\u5de5\u4f5c\u5217\u8868\ngit stash apply # \u6062\u590d\u88ab\u9690\u85cf\u7684\u5de5\u4f5c\uff0c\u4e0d\u5220\u9664\u9690\u85cf\u5de5\u4f5c\u5217\u8868\u4e2d\u7684\u8bb0\u5f55\ngit stash drop # \u5220\u9664\u9690\u85cf\u5de5\u4f5c\u5217\u8868\u4e2d\u7684\u8bb0\u5f55\ngit stash pop # \u6062\u590d\u9690\u85cf\u7684\u5de5\u4f5c\u5e76\u5220\u9664\u9690\u85cf\u5de5\u4f5c\u5217\u8868\u4e2d\u7684\u8bb0\u5f55\n<\/code><\/pre>\n<p>HEAD<\/p>\n<pre><code class=\"language-sh\">cat .git\/HEAD\n\/\/ git symbolic-ref HEAD\ngit checkout &lt;hash&gt;\ngit checkout master^\ngit checkout HEAD^\ngit checkout HEAD~4\ngit branch -f &lt;branchname&gt; HEAD~3\n<\/code><\/pre>\n<h1>\u76f8\u5173\u6587\u7ae0<\/h1>\n<ul>\n<li><a href=\"https:\/\/www.cnblogs.com\/zjiacun\/p\/6860521.html\">Git\u68c0\u51fa\u8fdc\u7a0b\u5e93\u7684\u5206\u652f\u7b49\u76f8\u5173\u64cd\u4f5c<\/a><\/li>\n<li><a href=\"https:\/\/git-scm.com\/book\/zh\/v2\/Git-%E5%88%86%E6%94%AF-%E5%8F%98%E5%9F%BA\">\u53d8\u57fa<\/a><\/li>\n<li><a href=\"https:\/\/feizhaojun.com\/?p=2280\">git\u653e\u5f03\u672c\u5730\u4fee\u6539<\/a><\/li>\n<li><a href=\"https:\/\/www.conventionalcommits.org\/\">\u7ea6\u5b9a\u5f0f\u63d0\u4ea4<\/a><\/li>\n<li><a href=\"https:\/\/www.atlassian.com\/git\/tutorials\/comparing-workflows\/gitflow-workflow\">Gitflow Workflow<\/a><\/li>\n<li><a href=\"https:\/\/www.atlassian.com\/git\/tutorials\/comparing-workflows\/feature-branch-workflow\">Git Feature Branch Workflow<\/a><\/li>\n<li><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/34223150\">\u4f18\u96c5\u7684\u63d0\u4ea4\u4f60\u7684 Git Commit Message<\/a><\/li>\n<\/ul>\n<h1>\u5b66\u4e60\u8def\u7ebf<\/h1>\n<pre><code>git init\ngit add\ngit commit\ngit status\ngit diff\n\ngit log\ngit reset --hard\ngit reflog\n\ngit checkout -- &lt;filename&gt;\n\ngit clone\ngit remote add\ngit push\ngit pull\n\ngit checkout\ngit branch\ngit merge\n\ngit stash\n<\/code><\/pre>\n<h1>\u5176\u4ed6<\/h1>\n<pre><code class=\"language-sh\">git diff HEAD -- file\ngit reset  # \u9000\u56de\u5230\u5de5\u4f5c\u533a\uff0c\u64a4\u9500\u4fee\u6539\u3001\u627e\u56de\u6587\u4ef6\uff0c\u9000\u56de\u5230\u6700\u65b0\u7248\u672c\uff0c\u5207\u6362\u5206\u652f\n\n# \u663e\u793a\u4fe1\u606f\u7c7b\u547d\u4ee4 \ngit ls-files -u \u663e\u793a\u51b2\u7a81\u7684\u6587\u4ef6\uff0c-s\u662f\u663e\u793a\u6807\u8bb0\u4e3a\u51b2\u7a81\u5df2\u89e3\u51b3\u7684\u6587\u4ef6\ngit ls-files --stage \u68c0\u67e5\u4fdd\u5b58\u5728stage\u7684\u6587\u4ef6\ngit log -g\u5219\u4f1a\u67e5\u8be2reflog\u53bb\u67e5\u770b\u6700\u8fd1\u505a\u4e86\u54ea\u4e9b\u52a8\u4f5c\uff0c\u8fd9\u6837\u53ef\u4ee5\u914d\u5408git branch \u6062\u590d\u4e4b\u524d\u56e0\u4e3a\u79fb\u52a8HEAD\u6307\u9488\u6240\u4e22\u5f03\u7684commit\u5bf9\u8c61\u3002\u5982\u679creflog\u4e22\u5931\u5219\u53ef\u4ee5\u901a\u8fc7git fsck --full\u6765\u67e5\u770b\u6ca1\u88ab\u5f15\u7528\u7684commit\u5bf9\u8c61\u3002 \ngit log -p -2 \u5bf9\u6bd4\u6700\u65b0\u4e24\u6b21\u7684commit\u5bf9\u8c61 \nlog -1 HEAD\ngit log --stat 1a410e \u67e5\u770bsha1\u4e3a1a410e\u7684commit\u5bf9\u8c61\u7684\u8bb0\u5f55\ngit blame -L 12,22 sth.cs \u5982\u679c\u4f60\u53d1\u73b0\u81ea\u5df1\u4ee3\u7801\u4e2d \u7684\u4e00\u4e2a\u65b9\u6cd5\u5b58\u5728\u7f3a\u9677,\u4f60\u53ef\u4ee5\u7528git blame\u6765\u6807\u6ce8\u6587\u4ef6,\u67e5\u770b\u90a3\u4e2a\u65b9\u6cd5\u7684\u6bcf\u4e00\u884c\u5206\u522b\u662f\u7531\u8c01 \u5728\u54ea\u4e00\u5929\u4fee\u6539\u7684\u3002\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\u4f7f\u7528\u4e86-L\u9009\u9879\u6765\u9650\u5236\u8f93\u51fa\u8303\u56f4\u5728\u7b2c12\u81f322\u884c\n\n# \u64a4\u9500\u7c7b\u547d\u4ee4 \n\u5982\u679c\u662f\u5355\u4e2a\u6587\u4ef6 \n1.use \"git reset HEAD &lt;file&gt;...\" to unstage \n\u5982\u679c\u5df2\u7ecf\u7528add \u547d\u4ee4\u628a\u6587\u4ef6\u52a0\u5165stage\u4e86\uff0c\u5c31\u5148\u9700\u8981\u4ecestage\u4e2d\u64a4\u9500\n\u7136\u540e\u518d\u4ece\u5de5\u4f5c\u533a\u64a4\u9500 \n2.use \"git checkout -- &lt;\/file&gt;&lt;file&gt;...\" to discard changes in working directory\ngit checkout a.txt  \u64a4\u9500a.txt\u7684\u53d8\u52a8\uff08\u5de5\u4f5c\u533a\u4e0a\u7684\u6587\u4ef6\uff09 \n\u5982\u679c\u662f\u591a\u4e2a\u6587\u4ef6 \ngit chenkout .\n\u5982\u679c\u5df2\u7ecfcommit \u4e86\uff0c\u5219\u9700\u8981 \ngit commit --amend \u6765\u4fee\u6539\uff0c\u8fd9\u4e2a\u53ea\u80fd\u4fee\u6539\u6700\u8fd1\u4e0a\u4e00\u6b21\u7684,\u4e5f\u5c31\u662f\u7528\u4e00\u4e2a\u65b0\u7684\u63d0\u4ea4\u6765\u8986\u76d6\u4e0a\u4e00\u6b21\u7684\u63d0\u4ea4\u3002\u56e0\u6b64\u5982\u679cpush\u4ee5\u540e\u518d\u505a\u8fd9\u4e2a\u52a8\u4f5c\u5c31\u4f1a\u6709\u5371\u9669\n$ git reset --hard HEAD \u653e\u5f03\u5de5\u4f5c\u533a\u548cindex\u7684\u6539\u52a8,HEAD\u6307\u9488\u4ecd\u7136\u6307\u5411\u5f53\u524d\u7684commit.\uff08\u53c2\u7167\u7b2c\u4e00\u5e45\u56fe\uff09\n\u8fd9\u6761\u547d\u4ee4\u540c\u65f6\u8fd8\u53ef\u4ee5\u7528\u6765\u64a4\u9500\u8fd8\u6ca1commit\u7684merge,\u5176\u5b9e\u539f\u7406\u5c31\u662f\u653e\u5f03index\u548c\u5de5\u4f5c\u533a\u7684\u6539\u52a8\uff0c\u56e0\u4e3a\u6ca1commit\u7684\u6539\u52a8\u53ea\u5b58\u5728\u4e8eindex\u548c\u5de5\u4f5c\u533a\u4e2d\u3002\n$ git reset --hard HEAD^ \u7528\u6765\u64a4\u9500\u5df2\u7ecfcommit\u7684\u5185\u5bb9(\u7b49\u4ef7\u4e8e git reset --hard HEAD~1) \u3002\u539f\u7406\u5c31\u662f\u653e\u5f03\u5de5\u4f5c\u533a\u548cindex\u7684\u6539\u52a8\uff0c\u540c\u65f6HEAD\u6307\u9488\u6307\u5411\u524d\u4e00\u4e2acommit\u5bf9\u8c61\u3002\ngit revert \u4e5f\u662f\u64a4\u9500\u547d\u4ee4\uff0c\u533a\u522b\u5728\u4e8ereset\u662f\u6307\u5411\u539f\u5730\u6216\u8005\u5411\u524d\u79fb\u52a8\u6307\u9488\uff0cgit revert\u662f\u521b\u5efa\u4e00\u4e2acommit\u6765\u8986\u76d6\u5f53\u524d\u7684commit,\u6307\u9488\u5411\u540e\u79fb\u52a8\n\n\n# \u5220\u9664\u7c7b\u547d\u4ee4\ngit mv a.txt b.txt \u628aa.txt\u6539\u540d\u4e3ab.txt\n\n# Merge\u7c7b\u547d\u4ee4\n\u5728\u51b2\u7a81\u72b6\u6001\u4e0b\uff0c\u9700\u8981\u89e3\u51b3\u51b2\u7a81\u7684\u6587\u4ef6\u4f1a\u4eceindex\u6253\u56de\u5230\u5de5\u4f5c\u533a\u3002\n1.\u7528\u5de5\u5177\u6216\u8005\u624b\u5de5\u89e3\u51b3\u51b2\u7a81 \n2.git add \u547d\u4ee4\u6765\u8868\u660e\u51b2\u7a81\u5df2\u7ecf\u89e3\u51b3\u3002 \n3.\u518d\u6b21commit \u5df2\u89e3\u51b3\u51b2\u7a81\u7684\u6587\u4ef6\u3002\n$ git reset --hard ORIG_HEAD \u7528\u6765\u64a4\u9500\u5df2\u7ecfcommit \u7684merge. \n$ git reset --hard HEAD \u7528\u6765\u64a4\u9500\u8fd8\u6ca1commit \u7684merge,\u5176\u5b9e\u539f\u7406\u5c31\u662f\u653e\u5f03index\u548c\u5de5\u4f5c\u533a\u7684\u6539\u52a8\u3002\ngit reset --merge ORIG_HEAD\uff0c\u6ce8\u610f\u5176\u4e2d\u7684--hard \u6362\u6210\u4e86 --merge\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u907f\u514d\u5728\u56de\u6eda\u65f6\u6e05\u9664working tree\u3002\n\n# \u6682\u5b58\u7c7b\u547d\u4ee4\n\u901a\u8fc7git stash\u5c06\u5de5\u4f5c\u533a\u6062\u590d\u5230\u4e0a\u6b21\u63d0\u4ea4\u7684\u5185\u5bb9\uff0c\u540c\u65f6\u5907\u4efd\u672c\u5730\u6240\u505a\u7684\u4fee\u6539\uff0c\u4e4b\u540e\u5c31\u53ef\u4ee5\u6b63\u5e38git pull\u4e86\uff0cgit pull\u5b8c\u6210\u540e\uff0c\u6267\u884cgit stash pop\u5c06\u4e4b\u524d\u672c\u5730\u505a\u7684\u4fee\u6539\u5e94\u7528\u5230\u5f53\u524d\u5de5\u4f5c\u533a\u3002\ngit stash: \u5907\u4efd\u5f53\u524d\u7684\u5de5\u4f5c\u533a\u7684\u5185\u5bb9\uff0c\u4ece\u6700\u8fd1\u7684\u4e00\u6b21\u63d0\u4ea4\u4e2d\u8bfb\u53d6\u76f8\u5173\u5185\u5bb9\uff0c\u8ba9\u5de5\u4f5c\u533a\u4fdd\u8bc1\u548c\u4e0a\u6b21\u63d0\u4ea4\u7684\u5185\u5bb9\u4e00\u81f4\u3002\u540c\u65f6\uff0c\u5c06\u5f53\u524d\u7684\u5de5\u4f5c\u533a\u5185\u5bb9\u4fdd\u5b58\u5230Git\u6808\u4e2d\u3002\ngit stash pop\/git stash pop stash@{0}: \u4eceGit\u6808\u4e2d\u8bfb\u53d6\u6700\u8fd1\u4e00\u6b21\u4fdd\u5b58\u7684\u5185\u5bb9\uff0c\u6062\u590d\u5de5\u4f5c\u533a\u7684\u76f8\u5173\u5185\u5bb9\u3002\u7531\u4e8e\u53ef\u80fd\u5b58\u5728\u591a\u4e2aStash\u7684\u5185\u5bb9\uff0c\u6240\u4ee5\u7528\u6808\u6765\u7ba1\u7406\uff0cpop\u4f1a\u4ece\u6700\u8fd1\u7684\u4e00\u4e2astash\u4e2d\u8bfb\u53d6\u5185\u5bb9\u5e76\u6062\u590d\u3002\n\u5728\u51fa\u73b0\u4e00\u4e2a\u6401\u7f6e\u6808\u7684\u60c5\u51b5\u4e0b\uff0c\u6bd4\u5982\u5982\u679c\u4f60\u60f3\u627e\u56de\u6808\u4e2d\u7684\u7b2c2\u4e2a\uff0c\u53ef\u4ee5\u7528 git stash apply stash@{1}\ngit stash list: \u663e\u793aGit\u6808\u5185\u7684\u6240\u6709\u5907\u4efd\uff0c\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u5217\u8868\u6765\u51b3\u5b9a\u4ece\u90a3\u4e2a\u5730\u65b9\u6062\u590d\u3002\ngit stash clear: \u6e05\u7a7aGit\u6808\u3002\u6b64\u65f6\u4f7f\u7528gitg\u7b49\u56fe\u5f62\u5316\u5de5\u5177\u4f1a\u53d1\u73b0\uff0c\u539f\u6765stash\u7684\u54ea\u4e9b\u8282\u70b9\u90fd\u6d88\u5931\u4e86\u3002\n<\/code><\/pre>\n<h1>FAQ<\/h1>\n<ul>\n<li>fatal: refusing to merge unrelated histories<br \/>\n<code>git pull origin master --allow-unrelated-histories<\/code><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u751f\u6210\u3001\u914d\u7f6e SSH key \u5148\u4f7f\u7528 ssh-keygen \u547d\u4ee4\u751f\u6210\u4e00\u4e2a key\uff0c\u8bb0\u5f97\u5e26\u4e0a\u4f60\u5728\u76f8\u5e94 git \u670d\u52a1\u5668\u7684\u7528\u6237\u540d&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[75,14],"tags":[76],"class_list":["post-1123","post","type-post","status-publish","format-standard","hentry","category-75","category--software","tag-git"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/feizhaojun.com\/index.php?rest_route=\/wp\/v2\/posts\/1123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/feizhaojun.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feizhaojun.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feizhaojun.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feizhaojun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1123"}],"version-history":[{"count":11,"href":"https:\/\/feizhaojun.com\/index.php?rest_route=\/wp\/v2\/posts\/1123\/revisions"}],"predecessor-version":[{"id":2700,"href":"https:\/\/feizhaojun.com\/index.php?rest_route=\/wp\/v2\/posts\/1123\/revisions\/2700"}],"wp:attachment":[{"href":"https:\/\/feizhaojun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feizhaojun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feizhaojun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}