Mikulas Dite Mikulas Dite - 1 year ago 62
Git Question

Git configure order in which files are merged

Our repository contains multiple files that are source code and one file that is a build artefact (compiled apiary blueprint for example).

There is a build script I can configure as merge driver for this file, but it fails if the source is not yet merged (or at least it builds from the merge state, which is not correct). Is there a way to tell git in what order it should try to merge files? There is a

, but that does not seem to be applied to

Answer Source

Update October 2016, for Git 2.11+ (Q4 2016)

There is a -O<orderfile> for git-diff, but that does not seem to be applied to git-merge.

There is now, but for git mergetool:

See commit 654311b (08 Oct 2016), and commit 57937f7, commit 08221e3, commit 8827b3a (07 Oct 2016) by David Aguilar (davvid).
Helped-by: Johannes Sixt (j6t).
(Merged by Junio C Hamano -- gitster -- in commit 5b4c45a, 17 Oct 2016)

mergetool: honor -O<orderfile>

Teach mergetool to pass "-O<orderfile>" down to git diff when specified on the command-line.

The git mergetool man page now includes:


Process files in the order specified in the <orderfile>, which has one shell glob pattern per line.
This overrides the diff.orderFile configuration variable.
To cancel diff.orderFile, use -O/dev/null.

Original answer August 2015

It seems the issue comes from the modifications done to the merge driver script, in addition of modifications to other files.

When you are merging your branch, the merge driver script isn't yet merged itself.

Why not update your merge driver script in a separate, dedicated branch, and merge that branch first.
Then merge your dev branch second.

An alternative approach would also uses a wrapper, as the OP Mikulas Dite comments:

Turns out it's really as simple a creating a custom merge wrapper, leaving the build artefact as -merge.
The wrapper runs git merge, and if there are no other unresolved files other than the artefact, run the build script.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download