# reject "backwards" merges

2 messages from 2014-12-12 to 2014-12-13. Participants: Patrick Donnelly, David Kastrup.
Thread: https://gitlist.dev/t/38172

## Patrick Donnelly, 2014-12-12 18:40

Subject: reject "backwards" merges
Message-ID: <CACh33FqHindeksHv7wcgu983oBSbm5G0ZswrQdTAz5tqgZdgjQ@mail.gmail.com>
URL: https://gitlist.dev/e/CACh33FqHindeksHv7wcgu983oBSbm5G0ZswrQdTAz5tqgZdgjQ%40mail.gmail.com

```
Is there a way to reject pushes that change the history of
first-parents, caused by a "backwards" merge? To clarify by example
(using branches instead of separate repositories):

$ git init
Initialized empty Git repository in /tmp/tmp.O0efpRrV4p/.git/
$ touch foo
$ git add foo
$ git commit -m initial
[master (root-commit) c4890b9] initial
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 foo
$ git branch b1
$ touch bar
$ git add bar
$ git commit -m bar
[master 9cb303e] bar
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bar
$ git checkout b1
Switched to branch 'b1'
$ touch baz
$ git add baz
$ git commit -m baz
[b1 4c618bc] baz
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 baz
$ git merge master
Merge made by the 'recursive' strategy.
 bar | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bar
$ git checkout master
Switched to branch 'master'
$ git merge b1
Updating 9cb303e..1b0a9d4
Fast-forward
 baz | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 baz
$ git log --graph
*   commit 1b0a9d4a011cd7e36c8c58b190aed0b450f06ca1
|\  Merge: 4c618bc 9cb303e
| | Author: Patrick Donnelly <>
| | Date:   Fri Dec 12 13:32:51 2014 -0500
| |
| |     Merge branch 'master' into b1
| |
| * commit 9cb303e2578af305d688abf62570ef31f3f113da
| | Author: Patrick Donnelly <>
| | Date:   Fri Dec 12 13:32:23 2014 -0500
| |
| |     bar
| |
* | commit 4c618bc094e82d9a5126a1c3fbc59921e41bd7b5
|/  Author: Patrick Donnelly <>
|   Date:   Fri Dec 12 13:32:46 2014 -0500
|
|       baz
|
* commit c4890b9bd590b34a9eb955d50e6e736729509a7c
  Author: Patrick Donnelly <>
  Date:   Fri Dec 12 13:31:46 2014 -0500

      initial

Here the desired first parent (HEAD^) would be commit
9cb303e2578af305d688abf62570ef31f3f113da. Unfortunately, the incorrect
merge reversed the line of parents. Is there a way to prevent this
from happening (via git-config) other than fixing the human?

-- 
Patrick Donnelly

```

## David Kastrup, 2014-12-13 09:47

Subject: Re: reject "backwards" merges
Message-ID: <877fxvdgpa.fsf@fencepost.gnu.org>
URL: https://gitlist.dev/e/877fxvdgpa.fsf%40fencepost.gnu.org
In-Reply-To: <CACh33FqHindeksHv7wcgu983oBSbm5G0ZswrQdTAz5tqgZdgjQ@mail.gmail.com>

```
Patrick Donnelly <batrick@batbytes.com> writes:

> Is there a way to reject pushes that change the history of
> first-parents, caused by a "backwards" merge? To clarify by example
> (using branches instead of separate repositories):
>
> Here the desired first parent (HEAD^) would be commit
> 9cb303e2578af305d688abf62570ef31f3f113da. Unfortunately, the incorrect
> merge reversed the line of parents. Is there a way to prevent this
> from happening (via git-config) other than fixing the human?

You'd have to do this in a push hook.  Before pushing, Git does not
really have a way to figure out which kind of branch a merge will land
on.

Most "reversed merges" probably come into being by having a fast-forward
in a series of zig-zagged merges.  Naturally the history before the
fast-forward can only be "the right way round" for one of the two
branches.

-- 
David Kastrup

```
