当我切换分支时,Git正在删除一个被忽略的文件 [英] Git is deleting an ignored file when i switch branches

查看:186
本文介绍了当我切换分支时,Git正在删除一个被忽略的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分支(我们称之为B),它忽略了某些其他分支(如分支A)中未被忽略的文件。当我从分支B切换到分支A时,再次返回到B,文件已被删除。



这是正常吗?我可以看出它是如何发生的,因为分支B认为它不在那里,而分支A认为它是这样的,所以当我回到B时它会清除它。但这有点令人讨厌。



有什么建议吗?

既然唯一可行的解​​决方案是随时追踪文件' f ',只能在分支 B ,,它将保护 fbis 如果从其他分支合并到 B

合并驱动程序将始终保持 B 版本的 fbis 内容,确保忽略的文件 f code> B 因为这些驱动程序(过滤器和合并)不在其他分支中提交,所以文件'f'在其他分支中进行了所有修改。

在分支 B 中,其内容永远不会改变,但对 f B 被检出时,它仍然会被恢复。



如果不需要恢复内容,则无需管理 fbis

只需保留过滤器驱动程序,并确保无论您对 b 中的 f 所作的任何修改,那些更改将永远不会被提交,有效地忽略 f 内容。


I have one branch (let's call it B) that ignores a certain file, which isn't ignored in some other branches (eg branch A). When i switch from branch B to branch A, then back to B again, the file has been deleted.

Is this normal? I can sort of see how it would happen, in the sense that branch B thinks it's not there, and branch A thinks that it is, so when i go back to B it 'tidies it away'. But it's kind of annoying.

Any suggestions?

解决方案

Since the only viable solution is to track the file 'f' at all times, you could add, only in branch B, a smudge/clean process with a gitattributes filter driver:

When checkouting branch B:

  • the smudge process would change:

    • save the content of f in a temp file
    • replace the content of f with one fbis file (a tracked file which would contain, for branch B, the "B content of f")
  • the clean process would:

    • save f content (as modified in B) in fbis (fbis gets committed with f modifications in branch B)
    • restore f content (with the temp file), meaning f is not committed (ignored in B)

You can add, still in branch B, a custom merge driver which will protect fbis in case of merges from other branches to B:
the merge driver will always keep B version of fbis content, making sure the ignored file f gets back its content whenever branch B is checked-out.

Since those drivers (filter and merge) are not committed in other branches, the file 'f' is committed in other branches with all its modifications.
In branch B, its content will never change, and yet the "local modifications" made to f are still restored whenever B is checked-out.

If that content restoration is not needed, you don't need to manage fbis.
Just keep the filter driver and you will be sure that whatever modification you do to f in branch B, those changes will never be committed, effectively ignoring f content.

这篇关于当我切换分支时,Git正在删除一个被忽略的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆