事后如何申请gitignore? [英] How to apply gitignore afterwards?
问题描述
我将本地存储库推送到GitHub。在提交我的代码的过程中,我忘了创建一个 .gitignore
文件。因此,我已经提交并随后推送了一些我不想在GitHub上(或在本地存储库中)的文件夹和文件。
现在我可以申请 .gitignore
,这样我可以删除一些不受欢迎的文件夹和文件吗?
git rm<不必要的文件和文件夹名称>
添加到您的 .gitignore
文件,它将从提交中删除它们。问题在于,除非您更改早期提交,否则它们将保留在历史记录中。如果这些文件中没有敏感数据,我会说现在就保留历史记录。如果您需要从存储库历史记录中删除敏感数据,请参阅 GitHub关于此主题的帮助文章 I pushed my local repository to GitHub. In the process of committing my code, I forgot to create a .gitignore
file. As a result, I have committed and subsequently pushed some folders and files that I didn't want on GitHub (or in my local repository, for that matter).
How can I apply .gitignore
now, so that I can remove some undesired folders and files going forward?
You can git rm <unnecessary file and folder names>
then add them to your .gitignore
file, which will remove them from that commit forward. The issue is that they will remain in the history unless you alter the earlier commits. If there is no sensitive data in those files, I'd say leave the history as is. If you need to remove sensitive data from your repository history, see GitHub's help article on the subject
这篇关于事后如何申请gitignore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!