gpt4 book ai didi

javascript - 删除 git status 中出现的未跟踪文件

转载 作者:行者123 更新时间:2023-11-28 17:50:13 24 4
gpt4 key购买 nike

当我执行git status时,会出现:

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: src/app.js
modified: src/view/view.js
modified: src/view/layout.js
modified: src/view/layout2.js
modified: src/view/layout3.js
modified: src/view/layout4.js
modified: src/view/layout5.js

Untracked files:
(use "git add <file>..." to include in what will be committed)

../hidemeplease.json

通常我会使用 git add -A 来一次性暂存所有更改,但这也会添加未跟踪的文件。所以现在我需要煞费苦心地一次暂存一个文件。

如何阻止未跟踪的文件出现在 git status 中?我不想删除该文件,只需忽略它,或者让 git status 忽略它。

我尝试做这样的事情:

git update-index --assume-unchanged hidemeplease.json

但没有效果。

有什么想法吗?

最佳答案

在 Git 中,未跟踪文件是指其路径名未出现在索引中的文件。

由于它不在索引中,因此您无法分辨 git update-index将索引条目标记为“假设不变”或“跳过工作树”。但这实际上是消息。

如果文件不在索引中,git status通常会提示,并且 git add .添加它。为了防止发生这些情况,请在 .gitignore 中列出文件的路径名。文件。

.gitignore文件包含 Git 将关闭的路径名列表,而不是自动添加。所以它确实应该被称为 .git-shut-up-about-these-files-and-do-not-auto-add-them 。不过,这个名字有点笨拙,因此 .gitignore .

请注意,如果文件的路径名位于索引中,则在 .gitignore 中列出该文件文件根本没有任何作用。这就是为什么当前的投诉是个好消息。

关于javascript - 删除 git status 中出现的未跟踪文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45723388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com