Search code examples
gitrebaseauto-generate

Git rebase failure with auto-generated file


I'm working on a code base where one file is autogenerated and changes very frequently. I find that rebasing my local branch usually results in falling back to three way merges and failure on this file. I then have to fix the file up and continue, but this can happen a number of times in one rebase and, due to the nature of the file, manual conflict resolution is usually pretty nasty. In fact, the whole process ends up in a nasty mess and a complete waste of time since there is no value added in attempting to merge this particular file.

Given that it is recreated as part of the build process anyway, is there a way I can tell Git to ignore this file during the rebase?

Please note that I've looked at other similar questions / answers but did not see anything that specifically addressed this (though please correct me if there's something out there.) Also, for the record I'm not keen on this type of file being in version control anyway, but I'm afraid I have no choice in the matter.


Solution

  • If the file is generated by your build, it should not be under version control in the first place.

    git rm --cached <path/to/file>
    echo <path/to/file> >> .gitignore
    git add .gitignore
    git commit -m "Removed <path/to/file> from version control"