git - gitignore 作用在哪里? git add、git commit 或 git push

标签 git

我在 git add . 之后添加了一个 .gitignore 文件。我想知道我是否可以继续 git commit 并推送它,并且 git 会忽略这些文件。

如果不是,我应该如何删除我 git add 编辑的文件。

.gitignore 影响哪里? git addgit commit 还是 git push

最佳答案

如果您的 gitignore 用于已添加的文件,您还需要:

  • git rm --cached thosefiles(从索引中删除它们,而不是从磁盘中删除)
  • git add -A(将记录这些删除以及您的 gitignore=
  • git 提交 并推送

关于git - gitignore 作用在哪里? git add、git commit 或 git push,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21621317/

相关文章:

Git递归更新子模块

windows - 如何 pull 和 check out 远程 Git 存储库

java - 如何在 jgit 中调用 git show --first-parent?

git - 仅解决较大团队中的部分 merge 冲突

git - 如何在我的 ionic 应用程序中显示 git sha

python - Microsoft azure devops python 管道失败,Bash 退出,代码为 '5'

git - 如何删除 "fatal: loose object"?

git - ERROR : Error fetching remote repo 'origin' , 返回状态码-1:

git - .gitignore 中定义的一些文件和文件夹在推送到 GitHub 时不会被忽略

git - 在 git 中转义在文件名中添加前导 "-"?