{"thread":{"id":"38172","subject":"reject \"backwards\" merges","startedAt":"2014-12-12T18:40:29Z","lastAt":"2014-12-13T09:47:29Z","messageCount":2,"participants":["Patrick Donnelly","David Kastrup"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"253643","messageId":"CACh33FqHindeksHv7wcgu983oBSbm5G0ZswrQdTAz5tqgZdgjQ@mail.gmail.com","threadId":"38172","inReplyTo":null,"subject":"reject \"backwards\" merges","fromName":"Patrick Donnelly","fromEmail":"batrick@batbytes.com","sentAt":"2014-12-12T18:40:29Z","receivedAt":"2014-12-12T18:40:29Z","isPatch":false,"sender":{"key":"batrick@batbytes.com","avatar":null},"body":"Is there a way to reject pushes that change the history of\nfirst-parents, caused by a \"backwards\" merge? To clarify by example\n(using branches instead of separate repositories):\n\n$ git init\nInitialized empty Git repository in /tmp/tmp.O0efpRrV4p/.git/\n$ touch foo\n$ git add foo\n$ git commit -m initial\n[master (root-commit) c4890b9] initial\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 foo\n$ git branch b1\n$ touch bar\n$ git add bar\n$ git commit -m bar\n[master 9cb303e] bar\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 bar\n$ git checkout b1\nSwitched to branch 'b1'\n$ touch baz\n$ git add baz\n$ git commit -m baz\n[b1 4c618bc] baz\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 baz\n$ git merge master\nMerge made by the 'recursive' strategy.\n bar | 0\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 bar\n$ git checkout master\nSwitched to branch 'master'\n$ git merge b1\nUpdating 9cb303e..1b0a9d4\nFast-forward\n baz | 0\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 baz\n$ git log --graph\n*   commit 1b0a9d4a011cd7e36c8c58b190aed0b450f06ca1\n|\\  Merge: 4c618bc 9cb303e\n| | Author: Patrick Donnelly <>\n| | Date:   Fri Dec 12 13:32:51 2014 -0500\n| |\n| |     Merge branch 'master' into b1\n| |\n| * commit 9cb303e2578af305d688abf62570ef31f3f113da\n| | Author: Patrick Donnelly <>\n| | Date:   Fri Dec 12 13:32:23 2014 -0500\n| |\n| |     bar\n| |\n* | commit 4c618bc094e82d9a5126a1c3fbc59921e41bd7b5\n|/  Author: Patrick Donnelly <>\n|   Date:   Fri Dec 12 13:32:46 2014 -0500\n|\n|       baz\n|\n* commit c4890b9bd590b34a9eb955d50e6e736729509a7c\n  Author: Patrick Donnelly <>\n  Date:   Fri Dec 12 13:31:46 2014 -0500\n\n      initial\n\nHere the desired first parent (HEAD^) would be commit\n9cb303e2578af305d688abf62570ef31f3f113da. Unfortunately, the incorrect\nmerge reversed the line of parents. Is there a way to prevent this\nfrom happening (via git-config) other than fixing the human?\n\n-- \nPatrick Donnelly\n"},{"id":"253678","messageId":"877fxvdgpa.fsf@fencepost.gnu.org","threadId":"38172","inReplyTo":"CACh33FqHindeksHv7wcgu983oBSbm5G0ZswrQdTAz5tqgZdgjQ@mail.gmail.com","subject":"Re: reject \"backwards\" merges","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2014-12-13T09:47:29Z","receivedAt":"2014-12-13T09:47:29Z","isPatch":false,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"Patrick Donnelly <batrick@batbytes.com> writes:\n\n> Is there a way to reject pushes that change the history of\n> first-parents, caused by a \"backwards\" merge? To clarify by example\n> (using branches instead of separate repositories):\n>\n> Here the desired first parent (HEAD^) would be commit\n> 9cb303e2578af305d688abf62570ef31f3f113da. Unfortunately, the incorrect\n> merge reversed the line of parents. Is there a way to prevent this\n> from happening (via git-config) other than fixing the human?\n\nYou'd have to do this in a push hook.  Before pushing, Git does not\nreally have a way to figure out which kind of branch a merge will land\non.\n\nMost \"reversed merges\" probably come into being by having a fast-forward\nin a series of zig-zagged merges.  Naturally the history before the\nfast-forward can only be \"the right way round\" for one of the two\nbranches.\n\n-- \nDavid Kastrup\n"}]}