0

How to force git merge to generate conflict on all file or all file that differ to generate conflict having whole old and whole new version, example of such file :

<<<<<<<<<<A
A
B
C
D
OLD
OLD
OLD
E
F
G
...
Z
============
A
B
C
D
NEW
NEW
NEW
EEEEEEE
FFFFF
GGG
...
Z

>>>>>>>>>>B

The idea is that I would like to merge manually having whole contents of two files, no metter if lines are identical or one branch is inheriting from whole previous, example:

$ echo ABC > file
$ git add file
$ git commit -m '+) file = ABC'
[master 6e91bce] +) file += ABC
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file
$ git checkout -b new_branch
Switched to a new branch 'new_branch'
$ echo DEF >> file 
$ git add file
$ git commit -m '+) file += DEF'
[new_branch 27e29bf] +) file += DEF
 1 files changed, 1 insertions(+), 0 deletions(-)
$ git checkout master
Switched to branch 'master'
$ git merge --no-ff new_branch
Automatic merge went well
$ cat file
ABC                                         
DEF

I understand the reason why git automatically addded "DEF" to "file". But I would like a way to force git "to think" :

  • master/file and new_branch/file differs
  • I will make a conflict with whole OLD and whole NEW version to let my users to manually resolve it

I've read other posts about making "merge driver", but it's far from clear to me how to make git using it. (Script is obvious, just a few lines).

P.S. For interested people: I do not use any merge tool. I'd like to merge TSV spreadsheets with DataSets and ResultsSets. In all cases when they differ (even if it's edit only on one branch), I'd like to process them manually with my own toolchain for processing those DataSets.

Grzegorz Wierzowiecki
  • 10,545
  • 9
  • 50
  • 88
  • But any half decent merge tool will show the contents of each revision. Why does the format of the merge conflict matter? And in your example, there is no conflict to resolve... could you be clearer what you're trying to do? – Hamish Jan 23 '12 at 09:24
  • Thanks @Hamish for pointing out what can be unclear to readers :). I would like to merge TSV spreadsheets with DataSets and ResultsSets with my own toolchain. So I do not want to use any merge tool. – Grzegorz Wierzowiecki Jan 23 '12 at 13:33
  • Simply tell git you want to use a different diff driver, rather than its normal built in diff tool, whether that be Beyond Compare 3 (BC3) or kdiff3. Theses tools can give you full file viewing. These settings can be added to the config file (see the man pages) – Philip Oakley Jan 23 '12 at 15:44
  • Please follow above example. Setting custom `mergetool` or `difftool` does not help, cause no conflict is raised -> so no resolving is raised. To sum it up: `git co master; git co -b new_branch ; echo NEWLINE >> file ; git ci -a -m '+'; git co master ; git merge new_branch` **will not generate any conflict**, even files are different. Question is, how to force git to raise such conflict? – Grzegorz Wierzowiecki Jan 23 '12 at 22:39

1 Answers1

2

You still need to tell Git that these should be treated as binary files which will result in a conflict if there is any difference. It's up to you now to investigate the files yourself with something like git show otherbranch:thefile and git show HEAD:thefile. Once you edit the file, you add it and git commit.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • [Pro Git: Git Attributes](http://progit.org/book/ch7-2.html) - according to your ans. I've found this. Do you have more related link recommendations? – Grzegorz Wierzowiecki Jan 23 '12 at 22:26
  • I've made `.gitattributes` with `* binary`, and now it recognizes files as binary. It does not help. Please follow above example. To sum it up: `git co master; git co -b new_branch ; echo NEWLINE >> file ; git ci -a -m '+'; git co master ; git merge new_branch` **will not generate any conflict**. – Grzegorz Wierzowiecki Jan 23 '12 at 22:30
  • Both sides did not change. You need both sides to change to get a conflict – Adam Dymitruk Jan 23 '12 at 22:33
  • Do you suggest to add some junky data at end of each file on size being merged, **commit this junk into repo**, to force conflict. Then remove it from end of all files **?** Adding junky data without committing, does not work, due to the error : `error: Your local changes to the following files would be overwritten by merge:` – Grzegorz Wierzowiecki Jan 24 '12 at 12:13
  • Even when I add junk data on merged side, when another is changed - it does not work. Git merges it with recursive strategy : `Auto-merging file Merge made by the 'recursive' strategy. file | Bin 22 -> 26 bytes` – Grzegorz Wierzowiecki Jan 24 '12 at 12:50
  • Then it's not recognizing it as a binary file. Git log --stat will show no line count change, but rather a byte count change. That's how you can quickly check if you properly designated the file as binary – Adam Dymitruk Jan 24 '12 at 18:01
  • Please, read carefully what I've cited: `22 -> 26 bytes` -> it's clearly about bytes – Grzegorz Wierzowiecki Jan 24 '12 at 19:15
  • What I am most afraid is that answer: "it's not possible, cause it's the way git works". But deep in my hart I believe `git` is a SCM Swiss army knife for all kind of Distributed Source Code management based on full revision snapshots :). – Grzegorz Wierzowiecki Jan 26 '12 at 18:29
  • Even thou - thanks for digging as much as you've done -> I've learned how to force `git` to treat file as binary :). – Grzegorz Wierzowiecki Jan 26 '12 at 18:30