{"id":457,"date":"2015-11-30T10:13:40","date_gmt":"2015-11-30T08:13:40","guid":{"rendered":"http:\/\/www.rinta-aho.org\/blog\/?p=457"},"modified":"2015-11-30T10:22:37","modified_gmt":"2015-11-30T08:22:37","slug":"how-to-merge-massive-formatting-only-commits-between-git-branches","status":"publish","type":"post","link":"http:\/\/www.rinta-aho.org\/blog\/how-to-merge-massive-formatting-only-commits-between-git-branches\/","title":{"rendered":"How to merge massive formatting-only commits between git branches"},"content":{"rendered":"<p class=\"moz-text-flowed\" lang=\"x-unicode\">*** As always, first backup everything (your git working directory etc.) ***<\/p>\n<p>Let&#8217;s assume formatting changed in branch A, and you&#8217;re working in branch B<\/p>\n<p>To make life easier, prepare two git clones, the other one is checked out<br \/>\nwith branch A (in dir gitA), the other one with branch B (in dir gitB).<br \/>\nYou need to have both branches in gitB up-to-date, so:<\/p>\n<pre>gitB&gt; checkout A\r\ngitB&gt; git pull\r\ngitB&gt; checkout B\r\ngitB&gt; git pull<\/pre>\n<p>Let&#8217;s assume the formatting-only megacommit has hashcode AAAA and the commit<br \/>\nbefore that has hashcode BBBB. You can check the latest commits to<br \/>\nbranch A like this:<\/p>\n<pre>gitA&gt; git log | less<\/pre>\n<p>First, merge A to B until the last commit before the formatting-only commit.<\/p>\n<pre>gitB&gt; git merge BBBB<\/pre>\n<p>Do the usual merge-stuff and commit. Do not push. For later analysis store<br \/>\nthe changed filenames:<\/p>\n<pre>gitB&gt; git diff --name-only A &gt; ..\/diffsbeforemerge<\/pre>\n<p>Close Eclipse or other clever software that is holding to your git working clone.<\/p>\n<p>Clean:<\/p>\n<pre>gitB&gt; git clean -d -x -f .<\/pre>\n<p>Copy all files to a safe place, e.g.<\/p>\n<pre>gitB&gt; cd ..\r\nxxxx&gt; tar cf gitB.tar gitB<\/pre>\n<p>Create another tar file without .git directory:<\/p>\n<pre>xxxx&gt; cp gitB.tar gitB-nogit.tar\r\nxxxx&gt; tar --delete -f gitB-nogit.tar gitB\/.git<\/pre>\n<p>Merge the formatting-only megacommit (hashcode AAAA):<\/p>\n<pre>xxxx&gt; cd gitB\r\ngitB&gt; git merge AAAA<\/pre>\n<p>Don&#8217;t worry about any conflicts&#8230; Just copy over the old files:<\/p>\n<pre>gitB&gt; cd ..\r\nxxxx&gt; tar xf gitB-nogit.tar<\/pre>\n<p>At this point, format all source codes with the same formatter as in branch A,<br \/>\ne.g. by starting Eclipse and importing the correct formatter and then selecting<br \/>\nall projects and &#8216;Source\/Format&#8217;.<\/p>\n<p>Then:<\/p>\n<pre>xxxx&gt; cd gitB\r\ngitB&gt; git add *\r\ngitB&gt; git commit -m \"Synchronized formatting with branch A.\"<\/pre>\n<p>Now it is a good time to check what was changed before you push your changes<br \/>\nanywhere. Remember that you have the backup of the situation before merging,<br \/>\nso you can just wipe away the gitB directory and extract the tarball gitB.tar.<\/p>\n<p>You can check that the formatting-only-merge did not add any new diffs to<br \/>\nbranches:<\/p>\n<pre>gitB&gt; git diff --name-only A &gt; ..\/diffsaftermerge\r\ngitB&gt; diff -u ..\/diffsbeforemerge ..\/diffsaftermerge<\/pre>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-32 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"http:\/\/www.facebook.com\/sharer.php?u=http%3A%2F%2Fwww.rinta-aho.org%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F457&#038;t=How%20to%20merge%20massive%20formatting-only%20commits%20between%20git%20branches&#038;s=100&#038;p&#091;url&#093;=http%3A%2F%2Fwww.rinta-aho.org%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F457&#038;p&#091;images&#093;&#091;0&#093;=&#038;p&#091;title&#093;=How%20to%20merge%20massive%20formatting-only%20commits%20between%20git%20branches\" style=\"font-size: 0px;width:32px;height:32px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"32\" height=\"32\" style=\"display: inline;width:32px;height:32px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/www.rinta-aho.org\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/addons\/extra-icons\/image\/social\/clearslate\/64x64\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-32 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=http%3A%2F%2Fwww.rinta-aho.org%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F457&#038;text=How%20to%20merge%20massive%20formatting-only%20commits%20between%20git%20branches\" style=\"font-size: 0px;width:32px;height:32px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"32\" height=\"32\" style=\"display: inline;width:32px;height:32px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/www.rinta-aho.org\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/addons\/extra-icons\/image\/social\/clearslate\/64x64\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-32 synved-social-resolution-single synved-social-provider-reddit nolightbox\" data-provider=\"reddit\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Reddit\" href=\"https:\/\/www.reddit.com\/submit?url=http%3A%2F%2Fwww.rinta-aho.org%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F457&#038;title=How%20to%20merge%20massive%20formatting-only%20commits%20between%20git%20branches\" style=\"font-size: 0px;width:32px;height:32px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"reddit\" title=\"Share on Reddit\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"32\" height=\"32\" style=\"display: inline;width:32px;height:32px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/www.rinta-aho.org\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/addons\/extra-icons\/image\/social\/clearslate\/64x64\/reddit.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-32 synved-social-resolution-single synved-social-provider-pinterest nolightbox\" data-provider=\"pinterest\" target=\"_blank\" rel=\"nofollow\" title=\"Pin it with Pinterest\" href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=http%3A%2F%2Fwww.rinta-aho.org%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F457&#038;media=&#038;description=How%20to%20merge%20massive%20formatting-only%20commits%20between%20git%20branches\" style=\"font-size: 0px;width:32px;height:32px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"pinterest\" title=\"Pin it with Pinterest\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"32\" height=\"32\" style=\"display: inline;width:32px;height:32px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/www.rinta-aho.org\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/addons\/extra-icons\/image\/social\/clearslate\/64x64\/pinterest.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-32 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=http%3A%2F%2Fwww.rinta-aho.org%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F457&#038;title=How%20to%20merge%20massive%20formatting-only%20commits%20between%20git%20branches\" style=\"font-size: 0px;width:32px;height:32px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"32\" height=\"32\" style=\"display: inline;width:32px;height:32px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/www.rinta-aho.org\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/addons\/extra-icons\/image\/social\/clearslate\/64x64\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-32 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=How%20to%20merge%20massive%20formatting-only%20commits%20between%20git%20branches&#038;body=http%3A%2F%2Fwww.rinta-aho.org%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F457\" style=\"font-size: 0px;width:32px;height:32px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"32\" height=\"32\" style=\"display: inline;width:32px;height:32px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/www.rinta-aho.org\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/addons\/extra-icons\/image\/social\/clearslate\/64x64\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>*** As always, first backup everything (your git working directory etc.) *** Let&#8217;s assume formatting changed in branch A, and you&#8217;re working in branch B To make life easier, prepare two git clones, the other one is checked out with branch A (in dir gitA), the other one with branch B (in dir gitB). You &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.rinta-aho.org\/blog\/how-to-merge-massive-formatting-only-commits-between-git-branches\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to merge massive formatting-only commits between git branches&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":4,"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":461,"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/posts\/457\/revisions\/461"}],"wp:attachment":[{"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.rinta-aho.org\/blog\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}