0

I use a few computers to work on a project and sync up the files quickly use git push and git pull. There is a file results.txt which is nice to have, but not mandatory, and each machine may happen to have altered the file.

When we do git pull and git push and this file resulted in merge conflict, is there just a quick way to tell git to ignore the conflict and proceeed? I think right now we need to git add results.txt and git commit -a. Is there a quick way just to keep one version or the other or even just use the conflict file and not worry about it? Or alternatively, is there a way to manage this file to work with git conflicts? I also thought of: if we use resultsSample.txt and it is part of the repo, and keep results.txt out of the repo and this is the file that our program outputs to, then it seems we could avoid the conflicts of the results, but just that at times we might want to copy results.txt to resultsSample.txt to update the content reasonably updated.

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • I would add it to the .gitignore file, such that the current version stays in the repo but is not updated – FloLie Nov 13 '20 at 08:21
  • @FloLie .gitignore will not ignore changes to a committed file. – piojo Nov 13 '20 at 08:22
  • https://stackoverflow.com/questions/9794931/keep-file-in-a-git-repo-but-dont-track-changes – FloLie Nov 13 '20 at 08:27
  • https://stackoverflow.com/questions/10697463/resolve-git-merge-conflicts-in-favor-of-their-changes-during-a-pull – Opri Nov 13 '20 at 08:29

1 Answers1

2

You can use git attributes to define a merge driver for the file. A simple merge driver that always keeps "our" version would be just using /bin/true:

git config --global merge.keep-ours.driver /bin/true

then add a .gitattributes in your repository:

results.txt merge=keep-ours
OhleC
  • 2,821
  • 16
  • 29