{"thread":{"id":"44708","subject":"git bug - merging JS / Node.js code with \"git merge --squash\"","startedAt":"2016-12-15T07:18:30Z","lastAt":"2016-12-15T18:10:54Z","messageCount":2,"participants":["Alexander Mills","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"307830","messageId":"CA+KyZp4HzsSOghKZnKgXEXy_gqw-9oTHveDHn1eRUY-_C6_jww@mail.gmail.com","threadId":"44708","inReplyTo":null,"subject":"git bug - merging JS / Node.js code with \"git merge --squash\"","fromName":"Alexander Mills","fromEmail":"alexander.d.mills@gmail.com","sentAt":"2016-12-15T07:12:03Z","receivedAt":"2016-12-15T07:18:30Z","isPatch":false,"sender":{"key":"alexander.d.mills@gmail.com","avatar":"https://gravatar.com/avatar/8accf19b85aa1020f85582e1f001860f853ce55767c226545a0825a2fcd99f04?d=mp&s=160"},"body":"@git-community\n\nI am on Git git version 2.7.4\n\nThis problem is happening on Ubuntu 16.04, but the same problem was\nalso happening when I was running on MacOS.\n\nI am consistently seeing merge bugs, when merging between branches of\na mostly Node.js project.\nI am seeing fairly bad merges that mangle the code in ways that seem\nto clearly show some sort of Git bug. Some of these merges were for\nfiles where there was likely not even a diff between the files.\nTBH I am no Git expert, but maybe I will learn something from this\ninvestigation.\n\nThe latest example of a mangled file is here:\nhttps://github.com/ORESoftware/suman/blob/staging/suman.conf.js\n\nYou can see some repeat code, and also there is a dangling brace which\nmeans that the file won't even \"compile\" with Node.js, using \"$ node\n-c\". Notice that this file was *not* a file where I recently  had to\nmanually merge code or manually fix a conflict, so I am hoping this is\nnot obvious operator error.\n\nHere is the script I am using to merge between branches:\nhttps://github.com/ORESoftware/suman/blob/dev/publish-suman.sh\n\nbasically it is doing the merge with this line:\n\ngit merge --squash -Xtheirs dev -m \"squashing\" &&\n\nThis is obviously very concerning because I can get very strange bugs\nthat I wouldn't expect, because I just assume that merges go well if\nthey succeed and it's hard to check for failure after that; even in a\ncompile statically typed language it could still prove difficult.\n\nI am doing a check to make sure all my files compile with \"node -c\"\nafter the merge, but even then Git could create mangled code that\nwould still pass a \"node -c\" check.\n\nPlease let me know if this is a known bug and if there is a good\nstrategy to avoid it.\n\nthanks!\n\n-- \nAlexander D. Mills\n(650)269-9502\nalexander.d.mills@gmail.com\n\nwww.linkedin.com/pub/alexander-mills/b/7a5/418/\n"},{"id":"307853","messageId":"xmqqwpf1ukpl.fsf@gitster.mtv.corp.google.com","threadId":"44708","inReplyTo":"CA+KyZp4HzsSOghKZnKgXEXy_gqw-9oTHveDHn1eRUY-_C6_jww@mail.gmail.com","subject":"Re: git bug - merging JS / Node.js code with \"git merge --squash\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-12-15T18:10:46Z","receivedAt":"2016-12-15T18:10:54Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Mills <alexander.d.mills@gmail.com> writes:\n\n> basically it is doing the merge with this line:\n>\n> git merge --squash -Xtheirs dev -m \"squashing\" &&\n\nThe order of command line parameters are \"dashed options and their\narguments first, then refs (and then pathspecs if exists), so you\nshould make it a habit to move that \"dev\" at the end of the command\nline.  This does not have anything to do with the issue you are\nasking for help, though.\n\nI suspect the problem is not in --squash but with -Xtheirs.  It is\n\"I give up correctly resolving conflicts and blindly take whatever\ncomes from their side, discarding what I did\".\n\nThe \"git merge\" command stops and asks a human to help resolving a\nconflict using their brain when it needs to because the command\nknows it itself does not have any but the human user has a better\none ;-).  -Xtheirs and -Xours disables this safety/sanity.\n\nIf you punt, it is expected that you would get garbage.  \n\nFor example, your side may have introduced a new function (or\nrenamed an existing one) near where their side made a change that\nresulted in conflicts.  Naturally, your side also would have added\nnew callsites to that new function (you wouldn't be adding an unused\nfunction).  Imagine in such a scenario that you asked \"discard what\nI did in the conflicted section and blindly take whatever they did\".\nWhat happens?  They may not have done anything near the places you\nadded calls to the new function and these sections of the code would\nmerge cleanly with or without -Xtheirs, but the actual new function\nyou added may be in the conflicted section that you asked to discard,\ntaking their changes.\n\n\n"}]}