1

I have some files specified in the ".git/info/exclude" file so that when I make a commit, those files are not staged/included in the commit. I also want to keep my local version of these files when I do a merge. I've set up a "ours" merge driver and set the ".git/info/attributes" file appropriately (I think); however, I don't think the driver's being used because I don't think git detects any conflicts in these files when the merge is attempted.

Here's my ".git/info/exclude" file (which is giving me what I want - these files never get staged):

/IDWA.Client/dmsConfig.json
/IDWA.Server.AppServer/client-config*.*
/IDWA.Server.AppServer/dmsConfig.json

Here's my ".git/info/attributes" file (which doesn't appear to be doing anything at all; again, I think because git is not detecting any conflicts when a merge is attempted):

/IDWA.Client/dmsConfig.json merge=ours
/IDWA.Server.AppServer/client-config*.* merge=ours
/IDWA.Server.AppServer/dmsConfig.json merge=ours

The driver configuration:

git config --global merge.ours.driver true

And, finally..

enter image description here

I just want to be able to do a git pull and never have to worry about these files.

aardvark
  • 328
  • 2
  • 14
  • 1
    You cannot exclude a tracked file. Your `merge=ours` directive will be obeyed when, during a merge, *both* branch tips differ from the *merge base* commit, but not if just one branch tip differs: Git will take that version, regardless of whose version it is. (There's nothing you can do about this other than put up with the annoyance, if you can't fix it properly upstream.) – torek Oct 07 '19 at 21:19
  • @torek - I was afraid of that. – aardvark Oct 07 '19 at 21:28

2 Answers2

1

Git is going very far out of its way to tell you that those files are part of whatever is coming from the other branch and that your files will be overwritten if you chose to go on with the operation.... so, git cannot guess what you would like to do in this case.. if you are absolutely sure that the files should not be part of the project at all, then go to the other branch and remove them from there and then try merging again (by the way... I'm writing this in a quite fast fashion because I don't have all the context of what's going on... but deleting those files from the other branch might have implications on your side, so be careful).

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • I would like to keep the files in the remote branch, but ignore them when pulling from that remote branch (keep my local ones instead). These are config files, which, depending on local setup of the application, may be different from developer to developer. Ideally, these files would be left completely untracked and/or replaced with a "template" file, and that's how I would do it, but the repository is not under my control. – aardvark Oct 07 '19 at 21:15
  • 1
    Oh, man.... sounds like a recipe for disaster.... did you delete the files from your branch? Perhaps what you want to try is `git update-index --assume-unchanged` on the files locally, not ignoring them. – eftshift0 Oct 07 '19 at 21:41
1

Here's my ".git/info/attributes" file (which doesn't appear to be doing anything at all;

That would work only in case of merge conflicts.

Since those files are already tracked, try:

git update-index --skip-worktree -- a file

See "Git - Difference Between 'assume-unchanged' and 'skip-worktree'".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250