Git is deleting an ignored file when i switch branches
git
Solution
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.
Problem
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?
Related problems
- How do I make Git forget about a file that was tracked, but is now in .gitignore?
- How can I have multiple working directories with Git?
- Have Git Select Local Version On Merge Conflict on a Specific File?
- How do you tell git to permanently ignore changes in a file?
- Is it possible to show all local branches at the same time in Windows Explorer?