{"id":52,"date":"2026-07-28T11:05:31","date_gmt":"2026-07-28T11:05:31","guid":{"rendered":"https:\/\/blog.levadny.com\/?p=52"},"modified":"2026-07-28T11:05:31","modified_gmt":"2026-07-28T11:05:31","slug":"delete-last-commit","status":"publish","type":"post","link":"https:\/\/blog.levadny.com\/?p=52","title":{"rendered":"Delete last commit"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Sometimes I watching how ours software engineers tried delete last error&#8217;s commit. And I decided to write little note about this.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remove commit from local machine.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">#Cancel last commit but save all last changes in index stage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">git reset &#8211;soft HEAD~1<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-text-align-left wp-block-paragraph\">#Cancel last commit but save all last changes in work directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">git reset &#8211;mixed HEAD~1<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">#Warning! Cancel last commit and remove all changes from work directory and index stage too<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">git reset &#8211;hard<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">And remove commit from server &#8211; I understand that this action is not good but it may be needed.<br>Sometimes options for Git in server side don&#8217;t allow change history. But you can try cancel commit.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">#rewrite some commit<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">git revert hashOfCommit<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">You can use this command for any commits but you must notice than you can create mess in repo.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And danger command for totally change history in repo.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">#danger command that can rewrite history in server<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">git rebase -i HEAD~N<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Where N &#8211; is count of last commits. After this command in opening editor we must find string with our error&#8217;s commit and change &#8220;pick&#8221; to &#8220;drop&#8221;. But it&#8217;s not good practice. You can use this method for remove any commits as a new commit and oldiest commit too.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On picture for example actions for git reset and git rebase.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"467\" height=\"293\" src=\"https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post1-1.jpg\" alt=\"\" class=\"wp-image-53\" srcset=\"https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post1-1.jpg 467w, https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post1-1-300x188.jpg 300w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"594\" height=\"594\" src=\"https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post2-1.jpg\" alt=\"\" class=\"wp-image-54\" srcset=\"https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post2-1.jpg 594w, https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post2-1-300x300.jpg 300w, https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post2-1-150x150.jpg 150w\" sizes=\"auto, (max-width: 594px) 100vw, 594px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"670\" src=\"https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post3-1.jpg\" alt=\"\" class=\"wp-image-55\" srcset=\"https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post3-1.jpg 640w, https:\/\/blog.levadny.com\/wp-content\/uploads\/2026\/07\/post3-1-287x300.jpg 287w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes I watching how ours software engineers tried delete last error&#8217;s commit. And I decided to write little note about this. Remove commit from local machine. #Cancel last commit but save all last changes in index stage git reset &#8211;soft HEAD~1 #Cancel last commit but save all last changes in work directory git reset &#8211;mixed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.levadny.com\/index.php?rest_route=\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.levadny.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.levadny.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.levadny.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.levadny.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=52"}],"version-history":[{"count":1,"href":"https:\/\/blog.levadny.com\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":56,"href":"https:\/\/blog.levadny.com\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions\/56"}],"wp:attachment":[{"href":"https:\/\/blog.levadny.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.levadny.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.levadny.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}