之后如何应用gitignore?

发布于 2024-12-14 23:43:18 字数 175 浏览 4 评论 0原文

我将本地存储库推送到了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乱世争霸 2024-12-21 23:43:18

您可以 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

且行且努力 2024-12-21 23:43:18

首先,删除意外添加到存储库中的 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.

清醇 2024-12-21 23:43:18

您必须从内存中删除它并重新添加它。 gitignore 将会生效。

已经回答了?

From memory you have to remove it and re-add it. Git ignore will then take effect.

Answered already?

朕就是辣么酷 2024-12-21 23:43:18

如果这是您的私人存储库并且您尚未发布它,请使用 filter-branch 编辑历史记录:

git filter-branch --index-filter '
  git rm -r --cached --ignore-unmatched bin;
' --all

然后,添加/编辑您的 .gitignore 文件:

>> .gitignore echo bin
git add .gitignore
git commit -m 'add gitignore files'

因为您已经已经发布了您的历史记录,最好不要重写它。只需删除 bin 目录并添加 .gitignore 文件

git rm -r bin
# add .gitignore
git commit -m 'remove and ignore bin folder'

If this is your private repo and you haven't published it yet, use filter-branch to edit history:

git filter-branch --index-filter '
  git rm -r --cached --ignore-unmatched bin;
' --all

Then, add/edit your .gitignore file:

>> .gitignore echo bin
git add .gitignore
git commit -m 'add gitignore files'

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

git rm -r bin
# add .gitignore
git commit -m 'remove and ignore bin folder'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文