2

I work on a project where multiple developers must edit code using a single project file. Most of the code they edit is actually located in separate code module files, but then they must share the single project file amongst themselves.

There are two types of things that the IDE writes to the project file:

  1. Important stuff: i.e. listings of module files that makeup the project
  2. Superfluous stuff: i.e. IDE dialog box X,Y position settings

Because the IDE has no concept of splitting out the superfluous stuff into per-user settings files, we wind up with merge conflicts all the time

Question: Does git provide an extension point (hook) that allows me to ignore the Superfluous Stuff when a user is merging a certain file type? My goal is to default to a "theirs/mine" type merge strategy for the Superfluous Stuff whilst handing the merging of the Important Stuff the same way it always does.

ThaDon
  • 7,826
  • 9
  • 52
  • 84
  • Git 2.24 (Q4 2019) does include a [**pre-merge-commit**](https://stackoverflow.com/a/58001118/6309) hook, which might help. – VonC Sep 18 '19 at 21:46

1 Answers1

2

You can use, strategy while merging

git merge --strategy-option theirs # or ours

Why do you need a hook for that? If you want to do it for some directory or file only, while merging you can use -

git checkout --theirs path/to/the/conflicted_file.php

As far as I know there is no pre-merge hook provided by git. If you use rebase instead of merge, then you can use pre-rebase hook. You can try using the prepare-commit-msg hook. The second argument will be merge if the commit is a merge or a .git/MERGE_MSG file exists.

prepare-commit-msg documentation

hspandher
  • 15,934
  • 2
  • 32
  • 45
  • I'm not sure if this is what I want though. Using your method I believe what would happen is it would auto-accept all the Superflous Stuff as `theirs` (good) , but it would also take their version of changes in the Important Stuff (bad) even if there really is a merge conflict that needs to be addressed. My goal is to auto-merge using `theirs` for only the Superfluous Stuff not the Important Stuff. Do you know what I mean? – ThaDon Sep 23 '15 at 16:19
  • How do you identify Superfluous stuff? – hspandher Sep 23 '15 at 16:21
  • I mean what do you mean by "Superfluous stuff". How do you expect git to differentiate? – hspandher Sep 23 '15 at 16:22
  • Well that's the thing, I don't expect git to be able to differentiate, that's why I'd like to know if there is an extension point I can exploit such that I could make the decision for it – ThaDon Sep 23 '15 at 16:41
  • I have changed my answer, see if that helps – hspandher Sep 23 '15 at 16:49
  • I like the `--theirs` option during merge, I think that will suffice! – ThaDon Nov 25 '15 at 21:46