GIT:切换分支时如何保留忽略的文件? [英] GIT: How to keep ignored files when switching branches?
问题描述
我有一个App.Local.config文件,每个开发人员都有自己的设置。我不希望此文件在GIT repo中检查版本,因为每次它都会被其他开发人员的更改覆盖。
因此,我从回购库中删除了该文件并将其添加到忽略文件中。但现在当开发人员切换分支时,App.Local.config将从其本地文件系统中删除。
最终,我想要的是:
- 新的开发克隆回购,获取App.Local.config的开始版本
- 开发对App.Local.config进行更改。
- dev开关分支,对App.Local.config的更改不会丢失,并且文件不会被删除。
我该怎么做?
谢谢。
可能发生的事情是,您从工作区中删除了该文件,但没有从索引中删除该文件。如果你这样做,git认为删除这个文件是一个变化,它会从那时开始删除它。
要走的路是删除不需要的文件希望从索引中跟踪
git rm --cached App.Local.config
然后将该文件添加到 .gitignore
这样做将没有更多的问题与文件
I have an App.Local.config file which each developer has their own settings in. I do not want this file checked versioned in the GIT repo as every time it would be overwritten by another developers changes.
So I deleted the file from the repo and added it to the ignore file. But now when developers switch branches, App.Local.config is deleted from their local filesystem.
Ultimately what i would like is:
- new dev clones repo, gets a starting version of App.Local.config
- dev makes changes to App.Local.config. Git will ignore changes and not stage/checkin
- dev switches branches, changes to App.Local.config will not be lost and file is not deleted.
How can I do that?
Thanks.
What probably happened is that you removed the file from your workspace but not from the index. If you did that git thinks that removing this file is a change and it will remove it from then on.
The way to go is to remove the file you don't want to track anymore from the index with
git rm --cached App.Local.config
and then add that file to the .gitignore
Doing that you will have no more problems with the file
这篇关于GIT:切换分支时如何保留忽略的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!