问题描述
我无法让 .gitignore
与 Visual Studio 2019 社区一起工作.
I cannot get .gitignore
to work with Visual Studio 2019 Community.
上图是团队资源管理器"的图片,标签,其中显示了要提交的文件列表的一部分.这些文件的显示目录x64 \ Debug位于C:\ Users \ 用户名 \ Source \ repos \ Tetris_System \ Tetris_Game下.C:\ Users \ 用户名 \ Source \ repos \ Tetris_System包含 .git
和 .vs
文件夹以及 .gitignore 代码>文件.
Above is an image of the "Team Explorer" tab showing a portion of the list of files which are to be committed. The directory in which these files appear, x64\Debug, is under C:\Users\username\Source\repos\Tetris_System\Tetris_Game. C:\Users\username\Source\repos\Tetris_System contains the .git
and .vs
folders and the .gitignore
file.
我有一个非常简单的 .gitignore
文件,其中只有一行:
I have a very simple .gitignore
file with a single line in it:
*.obj
我的理解是,这一行应该从提交列表中删除所有 *.obj
文件.这些 *.obj
文件是否应该从列表中消失?
My understanding is, that this single line should remove all the *.obj
files from the commit list. Shouldn't those *.obj
files disappear from the list?
根据先前的提交,所有这些 *.obj
都位于GitHub存储库上.
From previous commits, all those *.obj
are on the GitHub repository.
推荐答案
.gitignore
文件仅适用于未跟踪的文件.
The .gitignore
-file only works on untracked files.
Git将工作副本中的每个文件视为三之一:
Git sees every file in your working copy as one of three things:
-
tracked
-先前已暂存或提交的文件; -
untracked
-尚未暂存或提交的文件;或 -
ignored
-已明确告知Git忽略的文件.
tracked
- a file which has been previously staged or committed;untracked
- a file which has not been staged or committed; orignored
- a file which Git has been explicitly told to ignore.
如果您已跟踪 文件,则 .gitignore
文件不起作用.
If you have tracked files, the .gitignore
-file doesn't works.
要取消跟踪单个文件,即停止跟踪文件但不将其从系统中删除,请使用:
To untrack a single file, ie stop tracking the file but not delete it from the system use:
git rm --cached filename
要取消跟踪 .gitignore
中的每个文件(首先提交所有未完成的代码更改,然后运行):
To untrack every file in .gitignore
(first commit any outstanding code changes, and then run):
git rm -r --cached
这将从索引(登台区域)中删除所有更改的文件,然后运行:
This removes any changed files from the index (staging area), then run:
git add .
并提交:
git commit -m ".gitignore file is now working"
这篇关于.gitignore不适用于Visual Studio 2019的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!