Search code examples
gitgitlabgit-mergemerge-conflict-resolution

Ignoring specific line(s) from merge conflict evaluation?


In my project there's someFile, whose the very first two lines look like this:

// This file is automatically generated
// Generated on 25.08.2020 15:01:00

The time in the second line varies.

This second line is therefore an unnecessary source of merge conflicts for my team.

Is there a way to somehow make git ignore that second line when evaluating git merge conflicts?


Solution

  • In general, no, there is not. You should in general not check autogenerated files or other build products into the repository; this is one of many reasons why.

    If you really want to do this, there are some approaches you can take:

    • Use a smudge and clean filter to remove the date on check in and add it on checkout.
    • Use a custom merge driver in .gitattributes to merge the file specially. Every user performing a merge will be required to have that merge driver, and it will almost certainly not work for merges done by your hosting platform (because they won't have your merge driver).