How to I switch to a git branch that ignores files without deleting these files?

爷,独闯天下 提交于 2019-12-07 06:52:00

问题


I have branch master that ignores .idea in its .gitignore. From that, I created branch noIgnore that has no .gitignore.

I found that checkout master deletes .idea.

That's not the behavior I want. I want to keep .idea, just not track it, not on master. How do I do that?


回答1:


You could stop tracking changes for a file in repo

git update-index --skip-worktree .idea

Since you're tracking it in the other branch, then when you make changes you'll want to start tracking changes again

git update-index --no-skip-worktree .idea

When you get tired of doing this manually, you could create a post-checkout hook if on master, stop tracking, else start tracking.




回答2:


It removes .idea because that's what checkout does, it checks out master where there's no .idea. Try to add --no-track to your command.



来源:https://stackoverflow.com/questions/39088698/how-to-i-switch-to-a-git-branch-that-ignores-files-without-deleting-these-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!