无法让 git 停止跟踪 package-lock.json

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44600721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:47:47  来源:igfitidea点击:

Can't make git stop tracking package-lock.json

node.jsgitnpm

提问by Giedrius

With npm v5 here is now package-lock.jsonfile being created after npm install

使用 npm v5 现在package-lock.json是在之后创建文件npm install

It is recommended to commit this file, but I have issue that this file is different for some reason between my dev machine and my server. Even if I push that file to repo, after npm installon server, file changes.

建议提交这个文件,但我的问题是这个文件由于某种原因在我的开发机器和我的服务器之间是不同的。即使我将该文件推送到 repo,npm install在服务器上后,文件也会更改。

So now I'm attempting to make git untrack this file. After following numerous answers from other questions, I seem to have almost managed to do so, it's not tracked on dev machine, doesn't appear in the repo itself, but after I pull code to server and make npm install, it appears in modifiedfiles.

所以现在我试图让 git untrack 这个文件。在遵循其他问题的大量答案之后,我似乎几乎设法这样做了,它没有在开发机器上进行跟踪,也没有出现在 repo 本身中,但是在我将代码拉到服务器并 make 之后npm install,它出现在modified文件中。

File is in .gitignore, but server git for some reason ignores it.

文件在 中.gitignore,但服务器 git 出于某种原因忽略了它。

git check-ignore -v -n package-lock.json
::      package-lock.json
git check-ignore -v -n --no-index package-lock.json
.gitignore:10:package-lock.json package-lock.json 

Possibly relevant info:

可能的相关资料:

Dev machine: Windows 10. Server: Ubuntu 14.04. I'm pulling code to server using tags.

开发机器:Windows 10。服务器:Ubuntu 14.04。我正在使用标签将代码拉到服务器上。

回答by Andy

You need to remove it from your repo (git rm package-lock.json) in order for git to stop tracking it.

您需要将它从您的 repo ( git rm package-lock.json) 中删除,以便 git 停止跟踪它。

.gitignore only works for untracked files. If you have a tracked file that is also in your .gitignore, the fact that the file is tracked overrides the fact that it is also in .gitignore.

.gitignore 仅适用于未跟踪的文件。如果您的 .gitignore 中也有一个被跟踪的文件,则该文件被跟踪的事实会覆盖它也在 .gitignore 中的事实。

回答by techkuz

git update-index skip-worktree package-lock.json

Will keep file in the rep but stop tracking

将文件保留在代表中但停止跟踪