{"id":105406,"date":"2021-07-06T07:00:00","date_gmt":"2021-07-06T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=105406"},"modified":"2021-07-06T09:06:03","modified_gmt":"2021-07-06T16:06:03","slug":"20210706-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20210706-00\/?p=105406","title":{"rendered":"What happens if I use a squash instead of a true merge when performing one of the git tricks?"},"content":{"rendered":"<p>A customer wanted to know which of the git tricks I&#8217;ve shared still work if you use a squash instead of a true merge. For example, in the case of <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190918-00\/?p=102901\"> splitting a file in two while preserving line history<\/a>, can this be done with squashing?<\/p>\n<p>Many of the git tricks exploit the way git walks the commit graph, and squashing creates a different graph from merging. Specifically, squashing <i>throws away all our hard work<\/i> in building a specific commit graph. Instead, squashing takes all the changes and squashes them together into a single commit. It&#8217;s as if you made all the changes at one sitting and committed them as a unit.<\/p>\n<p>On the other hand, squashing works just fine with the tricks that involve a single non-merge commit. It just replaces one non-merge commit with an identical one.<\/p>\n<table class=\"cp3\" style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Trick<\/th>\n<th>Squashable?<\/th>\n<th>Notes<\/th>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20180323-01\/?p=98325\"> Merging instead of cherry-picking<\/a><\/td>\n<td>No<\/td>\n<td>Merging is the point<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190506-00\/?p=102478\"> Building a commit manually out of a tree<\/a><\/td>\n<td>Yes<\/td>\n<td>Creates a single non-merge commit<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190507-00\/?p=102480\"> Building a merge commit manually out of a tree<\/a><\/td>\n<td>No<\/td>\n<td>Result is a merge commit<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190508-00\/?p=102482\"> Building a throwaway commit in order to perform a combined cherry-pick-squash<\/a><\/td>\n<td>Yes<\/td>\n<td>Creates a single non-merge commit<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190509-00\/?p=102485\"> Changing a squash to a merge<\/a><\/td>\n<td>No<\/td>\n<td>Result is a merge commit (that&#8217;s the whole point)<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190510-00\/?p=102488\"> Squashing without git rebase<\/a><\/td>\n<td>Yes<\/td>\n<td>Creates a single non-merge commit<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190513-00\/?p=102490\"> Resetting by reusing an earlier tree<\/a><\/td>\n<td>No<\/td>\n<td>Result is a commit that needs to be merged<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190514-00\/?p=102493\"> Combining two files into one while preserving line history<\/a><\/td>\n<td>No<\/td>\n<td>Creates merge commits<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190515-00\/?p=102495\"> Combining two files into one while preserving line history, via manual octopus merging<\/a><\/td>\n<td>No<\/td>\n<td>Creates merge commits<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190916-00\/?p=102892\"> How do I split a file into two while preserving git line history?<\/a><\/td>\n<td>No<\/td>\n<td>Creates merge commits<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190917-00\/?p=102894\"> How to split out pieces of a file while preserving git line history v1<\/a><\/td>\n<td>No<\/td>\n<td>Creates merge commits<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190918-00\/?p=102901\"> How to split out pieces of a file while preserving git line history v2<\/a><\/td>\n<td>No<\/td>\n<td>Creates merge commits<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190919-00\/?p=102904\"> How to duplicate a file while preserving git line history<\/a><\/td>\n<td>No<\/td>\n<td>Creates merge commits<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20200921-00\/?p=104245\"> Converting a rebase to a merge<\/a><\/td>\n<td>No<\/td>\n<td>Creates merge commits<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20200928-00\/?p=104302\"> How can I bulk-revert an entire repo to an earlier commit?<\/a><\/td>\n<td>It depends<\/td>\n<td>Method 1 uses a single non-merge commit, but method 2 uses a merge<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20201005-00\/?p=104334\"> How can I bulk-revert a subdirectory of a repo to an earlier commit?<\/a><\/td>\n<td>Yes<\/td>\n<td>Creates a single non-merge commit<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>In many cases, the merge is where the magic is.<\/p>\n","protected":false},"author":1069,"featured_media":100998,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-105406","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>In many cases, the merge is where the magic is.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=105406"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105406\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/100998"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=105406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=105406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=105406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}