[lug] How do I get the merge I want?
David L. Anselmi
anselmi at anselmi.us
Tue Mar 4 16:15:40 MST 2014
Jeffrey S. Haemer wrote:
> I want to merge a pair of files, with hunks that differ marked the way
> they'd be by, say, "git merge":
So you want to run git merge on two files that aren't in git? Is there an option for that? Seems
like whatever git is using should be reusable. (Yes, I'm horribly idealistic.)
So merge isn't really the right thing to say, is it? With only 2 files all you have is a diff. But
I guess you want to see every line in both files, rather than the abbreviated hunks you usually see.
Is that right?
So it doesn't match your specified format, but does diff -C -1 (or -U -1) come close? And there's a
"roll your own format" option to diff, that probably isn't worth learning if you don't already
recognize it. (I'm a little surprised that using a negative number for -C/-U did what I expected.
Maybe it didn't and I didn't test hard enough.)
> This seems like a common-enough task, so there must be a command tailored
> to it. I just haven't found it yet. I can't, for example, even get merge(1)
> to do the job without a fake ancestor file that differs from both files
> exactly where they already differ, which begs the question.
> So far, the best I've found is this:
> $ diff3 -m file2 file1 file2
Yeah, so the issue is that a merge is applying two patches onto a common ancestor. So 3 files by
definition and it doesn't sound like that's what you have. It's typical Unix that if you give diff3
some nonsense about two of its files being the same it just does its job and comes up with something
useful. Sorry that it's not obvious but how many kinds of nonsense can you code for? (And you can
always make yourself a wrapper so that it's more obvious for your preferred style of nonsense.) :-)
> And yes, I could put the two versions into git in different branches and
> then call "git merge." :-)
Could you? What would be the common ancestor? I think git would just show you a diff (granted in
fancy git style, which might also be what you want).
Sorry if I've completely missed the point.
More information about the LUG