如何切换到忽略文件而不删除这些文件的git分支? [英] How to I switch to a git branch that ignores files without deleting these files?
问题描述
我有一个分支master
,它忽略了.gitignore
中的.idea
.
由此,我创建了没有.gitignore
的分支noIgnore
.
I have branch master
that ignores .idea
in its .gitignore
.
From that, I created branch noIgnore
that has no .gitignore
.
我发现checkout master
删除了.idea
.
那不是我想要的行为.我想保留.idea
,只是不跟踪它,而不是在master
上.我该怎么办?
That's not the behavior I want. I want to keep .idea
, just not track it, not on master
. How do I do that?
推荐答案
您可以停止跟踪存储库中文件的更改
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.
这篇关于如何切换到忽略文件而不删除这些文件的git分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!