Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I recently upgraded from Ubuntu 12.04 to 12.10 and at one point, it encountered an Apache config file conflict in apache2.conf. I didn't give me a merge option at that point, so I just rejected the new file and the installer saved the new file as apache2.conf.dpkg-dist.

I can diff the two files with diff apache2.conf apache2.conf.dpkg-dist and get just the lines that are different. But I want to manually merge the two sort of like how I resolve merge conflicts in SVN or git. How can I do that?

share|improve this question
    
Without a proper parser, you can only merge them manually –  warl0ck Oct 25 '12 at 23:48
add comment

3 Answers

Use vimdiff if you like vim. Otherwise, diffuse works great as well.

share|improve this answer
add comment

Version control has more information available when it resolves conflicts: it has not only your version and the other guy's version but also the common ancestor, and thus it can do a three-way merge. Here, the common ancestor is the original version of the configuration file in the distribution, or the official version that you last merged with your changes.

Unfortunately neither Ubuntu nor any other major distribution I know of makes it completely seamless to do three-way merges when a configuration file is updated. You can get close, however, with etckeeper. Etckeeper is an add-on for APT, the package management tool used by Debian and derivatives, that manages /etc in a version control system (Bazaar, Darcs, Git, Mercurial); it's been ported to other systems, including Yum in Fedora. I recommend using etckeeper; it's also a great way of keeping track of the changes you make in /etc.

Some programs manage their configuration files with ucf, but that's not something you have control of as a user.

More generally, when you have the ancestor and two versions, you can do a three-way merge with the merge utility shipped with RCS or with diff3 -m from diffutils.

There are also a great many interactive diff and merge programs. Emacs and Vim have interfaces for that, as do most diff viewers.

share|improve this answer
add comment

My personal favorite is kdiff3 - I do not know, if there is a Ubuntu-version for it. According to the homepage it just uses qt.

With that tool you can merge two (or three) files into a new one. Either by choosing a side for each difference, or by manually resolving the conflict.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.