Windows 上的 Git:为什么我突然有了以前被跟踪的未跟踪目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3492186/
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
Git on Windows: Why I suddenly have untracked directory that used to be tracked?
提问by Arnis Lapsa
When i hit 'git status', it shows 2 folders that contains files that are tracked long time ago:
当我点击“git status”时,它会显示 2 个文件夹,其中包含很久以前跟踪过的文件:
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# src/UI/Views/Shared/EditorTemplates/
# src/Web/helpers/
nothing added to commit but untracked files present (use "git add" to track)
Git GUI shows nothing as expected.
Git GUI 没有按预期显示任何内容。
Using portablegit 1.7.1, but tried 1.7.0.2 - same results.
使用便携式git 1.7.1,但尝试了 1.7.0.2 - 结果相同。
What can cause that?
什么会导致这种情况?
$ cat .gitignore
.nu/*
lib/*
*~
*.swp
*.swo
*_ReSharper*
doc/*
RAPLM.suo
RAPLM.5.1.ReSharper.user
src/*/bin/*
src/*/obj/*
src/*/Debug/*
src/*/Release/*
src/Domain/unused
@Charles Bailey
@查尔斯·贝利
lapsaarn@WW021198 /d/work/asdf (master)
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# src/UI/Views/Shared/EditorTemplates/
# src/Web/helpers/
nothing added to commit but untracked files present (use "git add" to track)
lapsaarn@WW021198 /d/work/asdf (master)
$ git add src/Web/helpers/
lapsaarn@WW021198 /d/work/asdf (master)
$ git add src/Web/helpers/*
lapsaarn@WW021198 /d/work/asdf (master)
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# src/UI/Views/Shared/EditorTemplates/
# src/Web/helpers/
nothing added to commit but untracked files present (use "git add" to track)
lapsaarn@WW021198 /d/work/asdf (master)
$
@Charles
@查尔斯
$ git ls-tree -r HEAD | grep -i helpers
100644 blob 843de27f850308786140a7c09f67b5ef99184630 src/web/helpers/HtmlHelperExtensions.cs
$ git ls-tree -r HEAD | grep -i helpers
100644 blob 843de27f850308786140a7c09f67b5ef99184630 src/web/helpers/HtmlHelperExtensions.cs
回答by VonC
Charles Baileycorrectly diagnosed the problem in the comments: "git add
" on a case insensitive Os.
查尔斯·贝利 (Charles Bailey)在评论中正确诊断了问题:“ git add
”在不区分大小写的 Os 上。
It is linked to issue 286of msysgit: "Case Sensitity of Directory Names", and the issue remains (again, for directories) even if you set core.ignorecase
to true.
它与msysgit 的第 286 个问题有关:“目录名称的大小写敏感度”,即使您设置为 true ,该问题仍然存在(同样,对于目录)core.ignorecase
。
When you add "src\Web
" (with a capital 'W
'), it won't add anything if your index already contains "src\web
" (lowercase 'w
').
当您添加“ src\Web
”(带有大写 ' W
')时,如果您的索引已经包含“ src\web
”(小写的w
' '),则不会添加任何内容。
A patch was proposed but rejected:
提出了一个补丁但被拒绝了:
The folder seems to be listed as untracked because
directory_exists_in_index()
tries to compare the old name to the new name, and ending up not finding a match for the new folder (even though the file inside it remains tracked!).
A very rude patch (inlined below) was written to try to work around the issue.
Now... for my minimal case, this works - the directory is no longer listed as untracked. But I strongly expect this to be a BROKEN patch for at least the following reason: Case insensitive comparison should break binary searching, as the casing should return the wrong position if I had more files in the index.
该文件夹似乎被列为未跟踪,因为
directory_exists_in_index()
尝试将旧名称与新名称进行比较,最终找不到新文件夹的匹配项(即使其中的文件仍被跟踪!)。
编写了一个非常粗鲁的补丁(内联)来尝试解决该问题。
现在......对于我的最小情况,这有效 - 该目录不再列为未跟踪。但我强烈希望这是一个 BROKEN 补丁,至少有以下原因:不区分大小写的比较应该破坏二进制搜索,因为如果索引中有更多文件,大小写应该返回错误的位置。
dir.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/dir.c b/dir.c
index e05b850..c55a15c 100644
--- a/dir.c
+++ b/dir.c
@@ -444,7 +444,7 @@ static enum exist_status directory_exists_in_index(const char
*dirname, int len)
struct cache_entry *ce = active_cache[pos++];
unsigned char endchar;
- if (strncmp(ce->name, dirname, len))
+ if (strnicmp(ce->name, dirname, len))
break;
endchar = ce->name[len];
if (endchar > '/')
--
1.6.4.msysgit.0.2.gcb017.dirty
So you need to:
所以你需要:
- change your '
Web
' into 'web
' in your working directory (filesystem) - OR change your '
web
' into 'Web
' in the index (git mv src/web src/Web
) in your index.
- 在您的工作目录(文件系统)中将您的“
Web
”更改为“web
” - 或者在您的索引中的索引 ( ) 中将您的
web
“Web
”更改为“ ”git mv src/web src/Web
。