我把以前由 Git 跟踪的文件放在.gitignore 列表中. 但是,文件在编辑后仍然显示在 git 状态。
当前回答
如果您创建了 gitignore 文件,使用命令如 echo node_modules >>.gitignore,它不会工作。
窗口终端存储文件在 UCS-2 LE BOM 和 git 似乎不接受它。
您可以通过在笔记本中打开并使用 UTF-8 编码重新存储。
此分類上一篇
它现在工作。
我认为他们需要纠正这一点,因为做echo“filetoignore” >>.gitignore实际上看起来非常有用
其他回答
特别是对于基于 IDE 的文件,我使用以下文件:
例如,对于 slnx.sqlite 文件,我刚刚完全解除它如下:
git rm {PATH_OF_THE_FILE}/slnx.sqlite -f
git commit -m "remove slnx.sqlite"
请记住,其中一些文件存储一些本地用户设置和项目偏好(类似于您打开的文件)。所以每次您浏览或在您的 IDE 中进行一些更改,该文件会被更改,因此它会检查并显示为未订购的更改。
对于我来说,文件在历史上仍然可用,我首先需要清除添加删除文件的命令: https://gist.github.com/patik/b8a9dc5cd356f9f6f980
下面的例子结合了最后3个命令
git reset --soft HEAD~3
git commit -m "New message for the combined commit"
推破的承诺 如果承诺已推到远程:
git push origin +name-of-branch
把它移动出来,承诺,然后把它移动回来。
这对我来说在过去已经工作了,但可能有更“迷人的”方式来实现这一点。
這不再是最新 Git 的問題(v2.17.1 在寫作時)。
.gitignore 文件最终忽略了跟踪但删除的文件. 您可以通过运行下列脚本来为自己测试此文件. 最终 git 状态声明应该报告“没有任何承诺”。
# Create an empty repository
mkdir gitignore-test
cd gitignore-test
git init
# Create a file and commit it
echo "hello" > file
git add file
git commit -m initial
# Add the file to gitignore and commit
echo "file" > .gitignore
git add .gitignore
git commit -m gitignore
# Remove the file and commit
git rm file
git commit -m "removed file"
# Reintroduce the file and check status.
# .gitignore is now respected - status reports "nothing to commit".
echo "hello" > file
git status