Working with git – Ignoring Merge Conflicts for a File
An issue I had to solve recently with git was how to ignore merge-conflicts for a single file in a repository. The application is an AngularJS application, and as is common with a Single Page Application (SPA) there is a single index.html file that is the starting point of the app. As part of the client-side build tooling, we are using two gulp plugins called wiredep and inject. These two plugins automatically add the <script> references to the index.html file for all of the javascript files in your application – including both the referenced libraries (e.g. angular.js) and the application specific js files (controllers, services etc). As a result, even though the developers almost never directly change the index.html file, it gets modified by the gulp tasks when the <script> references are added. So with each commit, git considers the index.html file to have been modified.
-
Define a custom merge driver for the index.html file in the .gitattributes file:
web/app/index.html merge=ours -
Next, update your .gitconfig file with the definition of the “ours” merge driver: