{"id":16546,"date":"2022-10-19T21:51:35","date_gmt":"2022-10-19T16:21:35","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/"},"modified":"2022-10-19T21:51:35","modified_gmt":"2022-10-19T16:21:35","slug":"solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/","title":{"rendered":"[Solved] How to make Git honor a cancelled merge that was not asked for?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-31317733\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"31317733\" data-parentid=\"31312742\" data-score=\"3\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p><code>git push<\/code> should normally fail if there are any new commits on the remote, that you don&#8217;t have on your local branch yet.<\/p>\n<p>In order to push, you cannot be missing any commits that the server has.<\/p>\n<p>In the example you posted, you seem to have made the commits <code>d091b80<\/code> and <code>217cb1f<\/code> on two different machines or two different local copies.<\/p>\n<p>When you were trying to push <code>217cb1f<\/code>, the server already had <code>d091b80<\/code>, while you didn&#8217;t have it in your local branch.<\/p>\n<p>Before git can push to the server, you will need to pull that other commit from the server.<\/p>\n<p>Usually that is something, that you would do manually. For some reason it seems like your <code>git push<\/code> is somehow invoking a <code>git pull<\/code>.<\/p>\n<p>While I couldn&#8217;t find a specific option to enable this sort of behavior (and wouldn&#8217;t suggest doing so either), I can see that some people would want git to behave this way.<br \/>\nIf you are using another persons config files for git or for your shell, I would have a look if there is anything that might cause this weird behavior.<\/p>\n<p>So how does the merge commit generally come about? Set aside the weird behavior of the push command and assume you had manually done a pull:<\/p>\n<h2>Git pull causes an unexpected merge commit<\/h2>\n<p>Git pull is doing two things:<\/p>\n<ul>\n<li>It fetches the remote<\/li>\n<li>It merges the remote branch into your local branch<\/li>\n<\/ul>\n<p>If there you have no new commits on your local machine, then you have a linear history and changes from the server will be included by fast-forwarding. This means that your local branch will simply be set to the same revision as the remote branch (visualise just having to walk down a little further on a single road).<\/p>\n<p>Imagine you have made a commit on your local branch, while a colleague (or yourself on a different machine) has pushed another change to the remote branch on the server:<br \/>\nThe two branches have now wandered into separate ways (visualise one road splitting into two here). When git pull tries to merge them together it will need to make a merge commit (visualise two roads merging into one).<\/p>\n<p>Alternatively you could do <code>git pull --rebase<\/code> or set the corresponding setting in your git config. This will tell git to apply your local changes to the &#8220;end of the road&#8221; of the server.<br \/>\nNote though, that a rebasing makes conflict resolution much harder and is generally more complicated than merges.<\/p>\n<hr>\n<p>Pushing as early as possible minimises branch diversion.<br \/>\nIf you haven&#8217;t made any new local commits yet, it is also a good idea to <code>pull<\/code> changes from the server <em>before<\/em> you are making a commit. That way, you are preventing your branches from diverting.<\/p>\n<p>A good way to do this is:<\/p>\n<pre><code>git stash       # This saves your uncommitted changes away as a draft\ngit pull        # Gets new commits from the remote\ngit stash pop   # Restores your uncommitted changes\n<\/code><\/pre>\n<hr>\n<h1>Abort a merge, while already editing the commit message<\/h1>\n<ol>\n<li>Empty the commit message in your editors buffer, save and exit.<br \/><sub>Any comments (prefixed with #) can stay as they are removed by git before evaluating (though this behaviour can be changed in the config).<br \/>\nIf you are vim user, I believe <code>dG:x<\/code> to be the fastest way to do this.<\/sub><\/li>\n<li>Run <code>git merge --abort<\/code><br \/>\nThis will make git try to restore the pre-merge state of your working copy.<br \/><sub>This command is available in git 1.7.4 or higher. For more info have a look at the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.kernel.org\/pub\/software\/scm\/git\/docs\/git-merge.html\">man entry for git-merge<\/a>.<\/sub><\/li>\n<\/ol>\n<hr>\n<h3>Why Ctrl+C does not do what one might expect<\/h3>\n<p>Simply pressing <kbd>Ctrl<\/kbd>+<kbd>C<\/kbd> will (in most, if not all cases) not do what you expect. When git launches a command line editor (such as vim, emacs or nano) that editor becomes the active\/current process of that shell.<\/p>\n<p>Press <kbd>Ctrl<\/kbd>+<kbd>C<\/kbd> will send a <code>SIGINT<\/code> signal to the current process. Meaning, sending <code>SIGINT<\/code> to your editor and not to git.<\/p>\n<p>If you were to use an editor, that fails (quits and returns an exit code other than 0) when receiving that signal, that might (though I have not tested it) abort the commit.<br \/>\nAs will an editor, that saves an empty buffer and quits.<br \/>\nIf you configure git to launch a GUI editor it will remain the frontmost process and a <code>SIGINT<\/code> should still abort the commit.<\/p>\n<p>Note, that in all three cases you will likely have the changes from the other branch in your working copy and you will need to clean them up (see step 2).<\/p>\n<hr>\n<p>For me personally (and a lot of extensive git users), this behaviour is what I would want from git. If you see that differently, you could file a bug report or feature request <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/git-scm.com\/community\">here<\/a>.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved How to make Git honor a cancelled merge that was not asked for? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] git push should normally fail if there are any new commits on the remote, that you don&#8217;t have on your local branch yet. In order to push, you cannot be missing any commits that the server has. In the example you posted, you seem to have made the commits d091b80 and 217cb1f on two &#8230; <a title=\"[Solved] How to make Git honor a cancelled merge that was not asked for?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/\" aria-label=\"More on [Solved] How to make Git honor a cancelled merge that was not asked for?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[329,4187],"class_list":["post-16546","post","type-post","status-publish","format-standard","hentry","category-solved","tag-git","tag-git-merge"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] How to make Git honor a cancelled merge that was not asked for? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] How to make Git honor a cancelled merge that was not asked for? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] git push should normally fail if there are any new commits on the remote, that you don&#8217;t have on your local branch yet. In order to push, you cannot be missing any commits that the server has. In the example you posted, you seem to have made the commits d091b80 and 217cb1f on two ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-19T16:21:35+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] How to make Git honor a cancelled merge that was not asked for?\",\"datePublished\":\"2022-10-19T16:21:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/\"},\"wordCount\":777,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"git\",\"git-merge\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/\",\"name\":\"[Solved] How to make Git honor a cancelled merge that was not asked for? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-19T16:21:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] How to make Git honor a cancelled merge that was not asked for?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] How to make Git honor a cancelled merge that was not asked for? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] How to make Git honor a cancelled merge that was not asked for? - JassWeb","og_description":"[ad_1] git push should normally fail if there are any new commits on the remote, that you don&#8217;t have on your local branch yet. In order to push, you cannot be missing any commits that the server has. In the example you posted, you seem to have made the commits d091b80 and 217cb1f on two ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/","og_site_name":"JassWeb","article_published_time":"2022-10-19T16:21:35+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] How to make Git honor a cancelled merge that was not asked for?","datePublished":"2022-10-19T16:21:35+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/"},"wordCount":777,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["git","git-merge"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/","url":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/","name":"[Solved] How to make Git honor a cancelled merge that was not asked for? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-19T16:21:35+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-make-git-honor-a-cancelled-merge-that-was-not-asked-for\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] How to make Git honor a cancelled merge that was not asked for?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/16546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=16546"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/16546\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=16546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=16546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=16546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}