简体   繁体   English

如何在不删除文件的情况下取消跟踪或忽略文件?

[英]How Do I untrack or ignore files without having them deleted in Git?

I'm a bit confused on how to use ignore and exclude with git. 我对如何在git中使用忽略和排除感到困惑。

I have a repo with 2 branches, master and production. 我有一个拥有2个分支,主分支和生产分支的仓库。

These 2 branches have config files that need to be different one is for the development server and one for the production server. 这两个分支的配置文件需要不同,一个用于开发服务器,一个用于生产服务器。

Git documentation states that ignore and exclude does not operate on tracked files. Git文档指出忽略和排除对跟踪的文件不起作用。 But if I untrack them, then they get deleted both locally and on the remote repo. 但是,如果我取消跟踪它们,则它们将在本地和远程存储库中被删除。

If I only apply locally either option, then when I merge or rebase any changes in other files, the configs are overwritten with the configs from the other branch. 如果仅在本地应用这两个选项,那么当我合并或重新配置其他文件中的所有更改时,该配置将被另一个分支中的配置覆盖。

I'm currently using Tower on Mac OSX. 我目前在Mac OSX上使用Tower。

Use --cached to remove the file from the index, but not the disk: 使用--cached从索引中删除文件,而不从磁盘中删除文件:

$ git rm --cached my_file

$ git status

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    my_file

Don't forget to commit your changes: 不要忘记提交您的更改:

$ git commit -m "Removed a my_file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM