简体   繁体   English

如何在git分支中“隔离”文件

[英]How can I “Isolate” file in a git branch

Is it possible to isolate a file in a git branch from the parent? 是否可以将git分支中的文件与父级隔离?

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. 我为每个分支都有一个msbuild配置文件,当从父级完成合并时,我不想更改文件。 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? 在perforce中,有一个名为“ isolate”的概念可以提供此功能,git是否有类似的功能?

gitattributes looked promising with merge=ours, but it looks like that has to be set up on each machine. gitattributes在merge = ours中看起来很有希望,但是看起来必须在每台机器上都设置它。

thanks! 谢谢!

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) 您的文件仍将被提交(第一次),并且尝试更新该文件只能通过显式地绕过预提交钩子来完成(因此,您知道它不是偶然完成的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM