我想阻止 Git 在 git status
中显示被忽略的文件,因为在 已更改但未更新 文件列表中包含大量文档和配置文件,导致列表呈现一半-无用。
Git显示这些文件正常吗?
我将忽略信息放在 Git 存储库根目录下的 .gitignore 文件中,使用 git add 时不会添加它们。 但似乎它们并不完全忽略两者,因为它们显示在上述列表中,并且不显示在 git ls-files --others -i --exclude-standard
打印的列表中。只有与 ~/.gitignore
中的模式匹配的文件才会显示在那里。
是不是因为前期我没有忽视它们,所以它们至少犯过一次?
I would like to stop Git from showing ignored files in git status
, because having tons of documentation and config files in the list of Changed but not updated files, renders the list half-useless.
Is it normal for Git to show these files?
I put the ignore information in a .gitignore
file in the root directory of the Git repository and they are not added when using git add .
but it seems that they are not fully ignored either, as they show up in the aforementioned list and do not show up in the list printed by git ls-files --others -i --exclude-standard
. Only files matched by the patterns in ~/.gitignore
show up there.
Could it be because at an earlier stage I didn't ignore them and they were thus committed at least once?
发布评论
评论(10)
我也遇到过这个问题,这可能是因为您在初始提交流程中将被忽略的目录/文件标记为“要跟踪”的 GIT 之后将其添加到 .gitignore 中。
因此,您需要像这样清除 git 跟踪缓存:
git rm --cached -r [文件夹/文件名]
可以在此处阅读更详细的说明:
http://www.frontendjunkie.com/2014 /12/stop-git-from-tracking-changes-to.html
上述命令还从远程 GIT 源中删除了文件夹/文件的残余内容。这样你的 GIT 仓库就变得干净了。
I've had this issue come up as well, it's probably because you added your ignored directory/files to .gitignore after they were marked as "to be tracked" by GIT in an initial commit flow.
So you need to clear the git tracking cache like so:
git rm --cached -r [folder/file name]
A more detailed explanation can be read here:
http://www.frontendjunkie.com/2014/12/stop-git-from-tracking-changes-to.html
The above command also removed the remnants of the folder/files from your remote GIT origin. So your GIT repos become clean.
问题可能是该文件仍在 git 缓存中。解决这个问题需要重置git缓存。
对于单个文件
对于整个项目
重置 git 缓存。如果您在未添加 .gitignore 文件时提交了项目,那么这是一个很好的命令。
提交更改
Problem can be that this file is still in the git cache. To solve this problem needs to reset git cache.
For single file
For whole project
Reset git cache. It is good command if you committed project when .gitignore file was not added.
Commit changes
这肯定有效,
git rm --cached -r [文件夹/文件名]
This surely works,
git rm --cached -r [folder/file name]
我假设您不想添加 tmp 目录(Visual Studio 平台)
1- 将以下行添加到本地 .gitignore 文件
3- 在本地备份并删除 tmp 文件夹。 (备份到其他地方。例如桌面?)
4- 将更改提交到本地而不是同步到远程(例如 github)。
完成这些步骤后,您的 tmp 目录将不会再次上传。
I assume you want not to add tmp directory (Visual Studio Platform)
1- add lines below to your local .gitignore file
3- backup and delete tmp Folder locally. (Backup somewhere else. eg desktop?)
4- Commit Changes to Local than Sync to Remote (eg. github).
After these steps your tmp directory wont be uploaded again.
在 .gitignore 文件中进行更改后。
请按照以下简单步骤进行
检查
after Make changes in .gitignore file.
follow these simple steps
To check
来自 man git-lsfiles:
就我个人而言,我倾向于将 doxygen 文件保留在我的源代码树中,因此我只是将其添加到我的 .gitignore (位于我的源代码树的最顶层目录中):
希望有帮助。
From man git-lsfiles:
Personally I tend to keep doxygen files in my source tree, so I simply added this to my .gitignore (which is in the topmost directory of my source tree):
Hope that helps.
以下步骤仅适用于未跟踪的文件。
此信息适用于以下配置:
将要忽略的文件列表放入以下位置的“排除”文件中。
“排除”文件的初始内容
“排除”文件的最终内容
Following steps work for untracked files only.
This info is applicable for following configuration:
Put list of files to be ignored in "exclude" file present at following location.
Initial content of "exclude" file
Final content of "exclude" file
根据接受的答案,您可以假设文件未更改,这样您在本地计算机上执行的任何操作都不会提交到远程分支。
类似于 git update-index --assume-unchanged src/main/resources/config.properties
其中 src/main.resources/config.properties 是在项目中查找该文件的路径示例。
现在,如果您想从存储库中完全删除文件,您可能需要使用
remove cached
而不是`git rm --cached这种情况可能适用于以下情况:
As per the accepted answer, you can assume the file as unchanged, so that whatever you do on your local machine is not commited to your remote branch.
Something like
git update-index --assume-unchanged src/main/resources/config.properties
where src/main.resources/config.properties is a sample for the path to find that file within your project.Now, if you want to remove the file completely from your repository, you may want to use
remove cached
instead as of `git rm --cachedThis scenario could be applicable on the following situation:
像这样
并且只会显示 myfolder 的状态
like this
And will show status only for myfolder
正如我发现在这篇文章中,
.gitignore
仅适用于未跟踪的文件。如果您将文件添加到存储库,您可以:或通过
编辑
从存储库中删除它们这篇文章也解释了这一点
As I found in this post,
.gitignore
only works for untracked files. If you added files to repository, you can:or remove them from repository by
Edit
This article explains that too