1

Is it possible to isolate a file in a git branch from the parent?

I have an msbuild configuration file for each of my branches, and when a merge is done from the parent, I don't want to file to change. Also, when I push the branch to the parent the file shouldn't be pushed.

In perforce there is a concept called "isolate" that offers this functionality, is there something similar for git?

gitattributes looked promising with merge=ours, but it looks like that has to be set up on each machine.

thanks!

nichos
  • 157
  • 1
  • 8
  • I will add this file to the [`.gitignore`](https://git-scm.com/docs/gitignore) ... – jmlemetayer Jul 25 '17 at 13:55
  • Files mentioned in `.gitignore` file will be ignored by git, they wont be committed. Read more [here](https://git-scm.com/docs/gitignore) – Shabin Muhammed Jul 25 '17 at 13:59
  • I still want them checked in & tracked however. The build config should remain with the branch. As I understand gitignore, I would need to "git rm --cached file.xml" which would remove it entirely. – nichos Jul 25 '17 at 14:06
  • 1
    *"gitattributes looked promising with merge=ours, but it looks like that has to be set up on each machine"* -- `.gitattribute` is a file you put in the working directory and commit to the repo. This solves the "set up on each machine" part in no time. – axiac Jul 25 '17 at 15:23

1 Answers1

2

I would add a pre commit hook to your repo to look for that specific file and fail if it tries to be included in a commit.

Your file would still be committed (the first time), and attempts at updating that file can only be done by explicitly bypassing the pre-commit hook (so you know it wasn't done accidentally)

Ben
  • 1,287
  • 15
  • 24
  • I'm going to accept this as the answer since it looks like it's the only way to do it. It's unfortunate that git doesn't allow for tracked files to be isolated to a branch. It seems like it would be a common thing. I'd really prefer to keep my build config in git than in jenkins somewhere. – nichos Jul 26 '17 at 14:24