threads / discuss / 38172

reject "backwards" merges

Subject: reject "backwards" merges

## tl;dr

2 messages between Dec 12, 2014 and Dec 13, 2014.

replies: 1people: 2as markdown or json

Patrick Donnelly· Dec 12, 2014, 18:40 UTC · lore

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· Dec 13, 2014, 09:47 UTC · re: Patrick Donnelly · lore

Re: reject "backwards" merges

Patrick Donnelly <batrick@batbytes.com> writes:
Show 8 quoted lines
> 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

← back to recent threads