How to I switch to a git branch that ignores files

2019-05-01 17:46发布

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?

标签: git gitignore
2条回答
聊天终结者
2楼-- · 2019-05-01 18:01

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.

查看更多
Bombasti
3楼-- · 2019-05-01 18:07

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.

查看更多
登录 后发表回答