之后如何应用gitignore?
我将本地存储库推送到了 GitHub。在提交代码的过程中,我忘记创建 .gitignore
文件。因此,我已提交并随后将一些我不需要的文件夹和文件推送到 GitHub(或我的本地存储库中)。
我现在如何应用.gitignore
,以便我可以删除一些不需要的文件夹和文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以 git rm <不必要的文件和文件夹名称> 然后将它们添加到您的
.gitignore
文件中,这会将它们从该提交中删除。问题是它们将保留在历史记录中,除非您更改早期的提交。如果这些文件中没有敏感数据,我会建议保留历史记录不变。如果您需要从存储库历史记录中删除敏感数据,请参阅有关该主题的 GitHub 帮助文章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首先,删除意外添加到存储库中的
bin
目录。您可以参考这里:http://help.github.com/remove-sensitive-data/
然后添加
.gitignore
并提交,然后推送到github。First, delete the
bin
directory added to the repo by accident. You may refer here:http://help.github.com/remove-sensitive-data/
Then add
.gitignore
and commit, and then push to github.您必须从内存中删除它并重新添加它。 gitignore 将会生效。
已经回答了?
From memory you have to remove it and re-add it. Git ignore will then take effect.
Answered already?
如果这是您的私人存储库并且您尚未发布它,请使用
filter-branch
编辑历史记录:然后,添加/编辑您的
.gitignore
文件:因为您已经已经发布了您的历史记录,最好不要重写它。只需删除 bin 目录并添加 .gitignore 文件
If this is your private repo and you haven't published it yet, use
filter-branch
to edit history:Then, add/edit your
.gitignore
file:Since you have already published your history, it's best practice not to rewrite it. Just remove the bin directory and add a .gitignore file