简体   繁体   English

如何从git中排除特定文件?

[英]How can I exclude a specific file from git?

I need to exclude dbconfig.php from git repository. 我需要从git存储库中排除dbconfig.php。 How can I remove it from the current indexing in the current repository? 如何将其从当前存储库中的当前索引中删除? Can I exclude it from being added to the repo even when running git add . 即使运行git add,我也可以将它排除在添加之外吗

Thanks! 谢谢!

First, remove the file from the index: 首先,从索引中删除文件:

git rm --cached dbconfig.php

Then, in the root of the repository, create .gitignore and add dbconfig.php to it. 然后,在库的根,创建.gitignore并添加dbconfig.php它。

git add .gitignore and git commit -m "new gitignore" and it should go missing the next time you do a git status or add . git add .gitignoregit commit -m "new gitignore" ,下次您执行git statusadd .时,它应该会丢失add .

Add a file named .gitignore in the repository and put a line in it: 在存储库中添加一个名为.gitignore的文件,并在其中添加一行:

dbconfig.php

Then git add .gitignore and commit it. 然后git add .gitignore并提交。

If you already committed the file before, you might want to reset to back before you committed it and re-add the other files, omitting the one you don't want tracked. 如果您之前已经提交过该文件,则可能要在提交之前重设回原来的位置,然后重新添加其他文件,而忽略不想跟踪的文件。 (Removing it and committing again would remove it from tracking, but the history would still be there - assuming the file contains sensitive data, you wouldn't want that.) (将其删除并再次提交会将其从跟踪中删除,但是历史记录仍将存在–假设文件包含敏感数据,则您不希望这样做。)

http://help.github.com/ignore-files/ http://help.github.com/ignore-files/

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

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