{"id":7132,"date":"2015-01-28T21:01:09","date_gmt":"2015-01-28T13:01:09","guid":{"rendered":"http:\/\/jpuyy.com\/?p=7132"},"modified":"2015-01-28T21:14:58","modified_gmt":"2015-01-28T13:14:58","slug":"git-delete-commit","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=7132","title":{"rendered":"git\u5220\u9664commit"},"content":{"rendered":"<p>\u5220\u9664\u6700\u8fd1\u7684\u4e00\u6b21 commit<\/p>\n<pre>git reset --hard HEAD~1<\/pre>\n<p>\u6216<\/p>\n<pre>git rebase -i HEAD~1<\/pre>\n<p>\u4f7f\u7528 git log \u7684\u65f6\u5019\u770b\u5230\u7684 sha1 \u7684\u63d0\u4ea4<\/p>\n<pre>git reset --hard <sha1-commit-id><\/pre>\n<p>\u5982\u679c\u4e0d\u5e78\u5df2\u7ecf\u63d0\u4ea4\uff0c\u5219\u9700\u8981\u5982\u4e0b\u64cd\u4f5c\u5c06\u63d0\u4ea4\u8fd8\u539f<\/p>\n<pre>git push origin HEAD --force<\/pre>\n<p>\u5c06\u6240\u6709\u4fee\u6539\u8fd8\u539f<\/p>\n<pre>git reset --hard HEAD<\/pre>\n<p>\u7ecf\u8fc7\u4e0a\u9762\u7684\u64cd\u4f5c\uff0c commit \u88ab\u5220\u6389\u4e86\uff0c\u4f60\u505a\u7684\u5de5\u4f5c\u4e5f\u5e9f\u4e86<\/p>\n<p>\u5982\u679c\u4f60\u53ea\u662f\u60f3\u8981\u64a4\u56de\u63d0\u4ea4\uff0c\u4f46\u5e76\u4e0d\u60f3\u628a\u5de5\u4f5c\u5e9f\u6389\uff0c\u53ef\u4ee5\u4f7f\u7528 &#8211;soft<\/p>\n<pre>git reset --soft HEAD~1<\/pre>\n<p>\u6211\u9519\u5220\u4e86\u4e00\u4e2a\u6587\u4ef6\u5e76\u63d0\u4ea4\uff0c\u73b0\u5728\u9700\u8981\u5c06\u8fd9\u6b21\u7684\u63d0\u4ea4\u6062\u590d<\/p>\n<pre>git revert c588349186b8dc3d074d64eca1408d2966a30cdc<\/pre>\n<p>\u7136\u540e\u663e\u793a\u5982\u4e0b\u4fe1\u606f\uff0c\u6211\u53ef\u4ee5\u5199\u4e0b\u4e3a\u4ec0\u4e48\u8981\u6536\u56de\u8fd9\u6b21\u63d0\u4ea4<\/p>\n<pre>\r\nRevert \"delete no use .vimrc\"\r\n\r\nThis reverts commit c588349186b8dc3d074d64eca1408d2966a30cdc.\r\n\r\n# Please enter the commit message for your changes. Lines starting\r\n# with '#' will be ignored, and an empty message aborts the commit.\r\n# On branch master\r\n# Your branch is ahead of 'origin\/master' by 1 commit.\r\n#   (use \"git push\" to publish your local commits)\r\n#\r\n# Changes to be committed:\r\n#       new file:   ubuntu\/home\/jpuyy\/.vimrc\r\n<\/pre>\n<p>\u7136\u540e\u8fd9\u5c31\u53d8\u6210\u4e86\u4e00\u6b21\u65b0\u7684\u63d0\u4ea4\uff0c\u4f46\u662f\u8fd4\u56de\u5230\u4e86\u4e4b\u524d\u7684\u7248\u672c.<\/p>\n<p>\u53c2\u8003\uff1a<br \/>\nhttp:\/\/stackoverflow.com\/questions\/1338728\/delete-commits-from-a-branch-in-git<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5220\u9664\u6700\u8fd1\u7684\u4e00\u6b21 commit git reset &#8211;hard HEAD~1 \u6216 git rebase -i HEAD~1 \u4f7f\u7528 git log \u7684\u65f6\u5019\u770b\u5230\u7684 sha1 \u7684\u63d0\u4ea4 git reset &#8211;hard \u5982\u679c\u4e0d\u5e78\u5df2\u7ecf\u63d0\u4ea4\uff0c\u5219\u9700\u8981\u5982\u4e0b\u64cd\u4f5c\u5c06\u63d0\u4ea4\u8fd8\u539f git push origin HEAD &#8211;force \u5c06\u6240\u6709\u4fee\u6539\u8fd8\u539f git reset &#8211;hard HEAD \u7ecf\u8fc7\u4e0a\u9762\u7684\u64cd\u4f5c\uff0c commit \u88ab\u5220\u6389\u4e86\uff0c\u4f60\u505a\u7684\u5de5\u4f5c\u4e5f\u5e9f\u4e86 \u5982\u679c\u4f60\u53ea\u662f\u60f3\u8981\u64a4\u56de\u63d0\u4ea4\uff0c\u4f46\u5e76\u4e0d\u60f3\u628a\u5de5\u4f5c\u5e9f\u6389\uff0c\u53ef\u4ee5\u4f7f\u7528 &#8211;soft git reset &#8211;soft HEAD~1 \u6211\u9519\u5220\u4e86\u4e00\u4e2a\u6587\u4ef6\u5e76\u63d0\u4ea4\uff0c\u73b0\u5728\u9700\u8981\u5c06\u8fd9\u6b21\u7684\u63d0\u4ea4\u6062\u590d git revert c588349186b8dc3d074d64eca1408d2966a30cdc \u7136\u540e\u663e\u793a\u5982\u4e0b\u4fe1\u606f\uff0c\u6211\u53ef\u4ee5\u5199\u4e0b\u4e3a\u4ec0\u4e48\u8981\u6536\u56de\u8fd9\u6b21\u63d0\u4ea4 Revert &#8220;delete no use .vimrc&#8221; This reverts commit c588349186b8dc3d074d64eca1408d2966a30cdc. # [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168],"tags":[],"class_list":["post-7132","post","type-post","status-publish","format-standard","hentry","category-git"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7132"}],"version-history":[{"count":5,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7132\/revisions"}],"predecessor-version":[{"id":7137,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7132\/revisions\/7137"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}