{"id":683,"date":"2011-01-22T00:04:20","date_gmt":"2011-01-22T07:04:20","guid":{"rendered":"http:\/\/sp2hari.com\/?p=683"},"modified":"2020-06-20T08:26:52","modified_gmt":"2020-06-20T08:26:52","slug":"git-reflog-and-git-force-push","status":"publish","type":"post","link":"https:\/\/sp2hari.com\/index.php\/2011\/01\/22\/git-reflog-and-git-force-push\/","title":{"rendered":"Git reflog and git force push"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sp2hari.com\/wp-content\/uploads\/2011\/01\/git.jpg\" alt=\"\" title=\"git\" width=\"100\" height=\"100\" class=\"alignright size-full wp-image-705\">Git reflog saves you from all screw-ups you do while using git.<\/p>\n<p>Here is a sample output of git reflog.<\/p>\n<p><code>hari@hari-desktop:\/var\/www\/recruit$ git reflog<br \/>\ne458f54 HEAD@{0}: checkout: moving from test1 to e458f54fe99202c82c2690be4fa2fe2d7aa7be32^0<br \/>\na3281d1 HEAD@{1}: checkout: moving from master to test1<br \/>\nf265802 HEAD@{2}: checkout: moving from test1 to master<br \/>\nef08492 HEAD@{3}: ORIG_HEAD: updating HEAD<br \/>\ne458f54 HEAD@{4}: commit: Implement phpunit testcase.<br \/>\n1ecf2c3 HEAD@{5}: commit: Bug#1 : MCQ Choices displayed in questions.<br \/>\nf265802 HEAD@{6}: checkout: moving from test1 to f265802d1d65a9ac92bf9f6414d8f468444cce66^0<br \/>\nec280c6 HEAD@{7}: checkout: moving from release to test1<br \/>\nf265802 HEAD@{8}: merge master: Fast-forward<br \/>\nccec6c4 HEAD@{9}: checkout: moving from master to release<br \/>\n<\/code><\/p>\n<p>All your commits, checkouts, pull, merges are logged in here. To, reset the git to any point in there, we use the following command.<\/p>\n<p><code>git reset --hard &lt;commit-id&gt;<\/code><\/p>\n<p>But if you push this to the git, you will find that the commit is rejected now. To forcefully push your new HEAD to server, we use the following command.<\/p>\n<p><code>git push origin +&lt;branch_name&gt; <\/code><\/p>\n<p><strong>+ before the branch name forcefully pushes the branch (even if your current branch is behind the origin).<\/strong><br \/>\nNOTE: Please be careful when you use the command above. You might lose all the changes made by others (temporarily) if you use it. Of course, using reflog + reset, you can get back the changes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git reflog saves you from all screw-ups you do while using git. Here is a sample output of git reflog. hari@hari-desktop:\/var\/www\/recruit$ git reflog e458f54 HEAD@{0}: checkout: moving from test1 to e458f54fe99202c82c2690be4fa2fe2d7aa7be32^0 a3281d1 HEAD@{1}: checkout: moving from master to test1 f265802 HEAD@{2}: checkout: moving from test1 to master ef08492 HEAD@{3}: ORIG_HEAD: &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-683","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/posts\/683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/comments?post=683"}],"version-history":[{"count":12,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/posts\/683\/revisions"}],"predecessor-version":[{"id":1348,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/posts\/683\/revisions\/1348"}],"wp:attachment":[{"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/media?parent=683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/categories?post=683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sp2hari.com\/index.php\/wp-json\/wp\/v2\/tags?post=683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}