Pycharm对Git感到奇怪(树条目中的文件名包含反斜杠)

时间:2019-12-15 16:01:10

标签: git pycharm git-clone backslash

我刚有了一台新笔记本电脑,想用pycharm克隆我的大学git存储库。

每当我尝试使用Git bash / GUI或Pycharm克隆存储库时,都会失败并显示错误消息,

  

树条目中的文件名包含反斜杠:'Aufgabe4a.py#coding = utf-8   ...

内部错误是提到的文件的完整内容。

因为这是我大学的仓库,所以我不能只是去重命名不是我的文件。 奇怪的是,这在我的桌面上不会发生。我可以在那里克隆仓库。

  • 两台机器都运行Windows 10和最新版本的Git / Pycharm。
  • SSH配置正确,我也无法使用HTTPS进行克隆。

我很期待您的建议,因为我需要此仓库来进行练习,但并不总是可以访问我的桌面。

编辑:存储库中没有单个文件的名称中包含反斜杠。我浏览了网站和“工作副本”,这是一个iOS应用程序,用于预览Git存储库。

这些是在笔记本电脑上使用Git调试时的结果:

18:28:45.034704 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
18:28:45.036676 git.c:439               trace: built-in: git clone git@*removed*.git
Cloning into 'uebungen'...
18:28:45.093121 run-command.c:663       trace: run_command: unset GIT_DIR; ssh git@*university URL* 'git-upload-pack '\''*university repo*'\'''
18:28:48.140893 run-command.c:663       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 8492 on DESKTOP-QNIF5QA' --check-self-contained-and-connected
18:28:48.155482 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
18:28:48.157663 trace.c:375             setup: git_dir: C:/Users/*removed*/uebungen/.git
18:28:48.157663 trace.c:376             setup: git_common_dir: C:/Users/*removed*/uebungen/.git
18:28:48.157663 trace.c:377             setup: worktree: C:/Users/*removed*
18:28:48.157663 trace.c:378             setup: cwd: C:/Users/*removed*
18:28:48.157663 trace.c:379             setup: prefix: (null)
18:28:48.158012 git.c:439               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 8492 on DESKTOP-QNIF5QA' --check-self-contained-and-connected
remote:
remote: Enumerating objects: 828, done.
remote:
(...)
remote: Counting objects: 100% (828/828), done.
remote:
(...)
remote:
remote: Compressing objects: 100% (380/380), done.
remote: Total 1184 (delta 490), reused 725 (delta 430)
error: filename in tree entry contains backslash: 'Aufgabe4a.py# coding=utf-8
import random #Liste für die Auswahlmöglichkeiten für den Rechner list = ["Schere", "Stein", "Papier"] #Eingabemöglichkeit für den Benutzer print("Versuchen Sie ihr Glück in Schere, Stein, Papier!") w = (raw_input("Bitte wählen sie Schere, Stein, oder Papier:")) # if w == "Schere":     print("Sie haben Schere gewaehlt!\n") else:     if w == "Stein":         print("Sie haben Stein gewaehlt!\n")     else:         if w == "Papier":             print("Sie haben Papier geweahlt!\n")         else:             print("Sie haben keine zugelassene Eingabe getaetigt!")             exit() #Wahl des Rechners wird, sowie der Ausgang des Spiels entschieden x = list[random.randint(0, 2)] print("Ihr Gegner hat " + x + " gewaehlt!\n")  if w == "Schere":     if x == "Schere":         print("Sie haben unentschieden gespielt!")     else:         if x == "Stein":             print("Stein schleift Schere, Sie haben verloren!")         else:             if x == "Papier":                 print("Schere schneidet Papier, Sie haben gewonnen!") elif w == "Stein":     if x == "Schere":         print("Stein schleift Schere, Sie haben geweonnen!")     elif x == "Stein":         print("Sie haben unentschieden gespielt!")     elif x == "Papier":         print("Papier umfaltet Stein, Sie haben verloren!") elif w == "Papier":     if x == "Schere":         print("Schere schneidet Papier, Sie haben verloren!")     elif x == "Papier":         print("Sie haben unentschieden gespielt!")     elif x == "Stein":         print("Papier umfaltet Stein, Sie haben gewonnen!")'
fatal: Not all child objects of 9(...)c are reachable
fatal: index-pack failed

这是台式机上的调试输出:

21:38:07.768170 exec-cmd.c:237          trace: resolved executable dir:C:/Program Files/Git/mingw64/bin
21:38:07.769170 git.c:440               trace: built-in: git clone git@*uni repo*.git
Cloning into 'uebungen'...
21:38:07.783173 run-command.c:663       trace: run_command: unset GIT_DIR; ssh git@*uni domain* 'git-upload-pack '\''*repo*.git'\'''
21:38:08.587244 run-command.c:663       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 14672 on Leo-PC' --check-self-contained-and-connected
21:38:08.602247 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
21:38:08.604247 trace.c:377             setup: git_dir: C:/Users/*removed*/uebungen/.git
21:38:08.604247 trace.c:378             setup: git_common_dir: C:/Users/*removed*/uebungen/.git
21:38:08.604247 trace.c:379             setup: worktree: C:/Users/*removed*
21:38:08.604247 trace.c:380             setup: cwd: C:/Users/*removed*
21:38:08.604247 trace.c:381             setup: prefix: (null)
21:38:08.604247 git.c:440               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 14672 on Leo-PC' --check-self-contained-and-connected
remote:
remote: Enumerating objects: 852, done.
(...)                                                                     remote: Counting objects: 100% (852/852), done.
(...)                                                                        remote: Compressing objects: 100% (373/373), done.
remote: Total 1208 (delta 508), reused 792 (delta 461)
Receiving objects: 100% (1208/1208), 6.24 MiB | 36.54 MiB/s, done.
Resolving deltas: 100% (680/680), done.
21:38:09.614724 run-command.c:663       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
21:38:09.628565 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
21:38:09.630566 trace.c:377             setup: git_dir: C:/Users/*removed*/uebungen/.git
21:38:09.630566 trace.c:378             setup: git_common_dir: C:/Users/*removed*/uebungen/.git
21:38:09.630566 trace.c:379             setup: worktree: C:/Users/*removed*
21:38:09.630566 trace.c:380             setup: cwd: C:/Users/*removed*
21:38:09.630566 trace.c:381             setup: prefix: (null)
21:38:09.630566 git.c:440               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
21:38:09.639568 chdir-notify.c:65       setup: chdir from 'C:/Users/*removed*' to 'C:/Users/*removed*/uebungen'
21:38:09.639568 chdir-notify.c:40       setup: reparent packed-refs to 'C:/Users/*removed*/uebungen/.git/packed-refs'
21:38:09.639568 chdir-notify.c:40       setup: reparent files-backend $GIT_DIR to 'C:/Users/*removed*/uebungen/.git'
21:38:09.639568 chdir-notify.c:40       setup: reparent files-backend $GIT_COMMONDIR to 'C:/Users/*removed*/uebungen/.git'

3 个答案:

答案 0 :(得分:3)

git-for-windows存储库中存在一个未解决的问题(针对 v2.24

Git 2.24 breaks existing repositories: filename in tree entry contains backslash

用户carlescufi建议的解决方法是禁用core.protectNTFS

git config --global core.protectNTFS false

在此处引用git docs

  

core.protectNTFS

     

如果设置为true,则不允许签出可能导致   NTFS文件系统的问题,例如与8.3“短”冲突   名称。在Windows上默认为true,在其他地方默认为false。

答案 1 :(得分:3)

使用Git 2.25(2020年第一季度),该问题应得到解决。
对Windows的Git的早期更新声明,如果树对象中包含带有反斜杠的路径组件,则该树对象无效,该组件过于严格,已得到纠正。

Windows用户唯一需要保护的是防止此类路径(或其文件系统无法检出的任何路径)进入索引。

请参见commit 224c7d7Johannes Schindelin (dscho)(2019年12月31日)。
(由Junio C Hamano -- gitster --commit a578ef9中合并,2020年1月6日)

mingw:仅测试索引条目的反斜杠,而不测试树条目

签名人:Johannes Schindelin

从v2.24.1(2)开始,在克隆以前包含名称带有反斜杠的文件的存储库期间,Git for Windows会显示以下错误:

error: filename in tree entry contains backslash: '\'

这个想法是为了防止Git甚至尝试写文件名中带有反斜杠的文件:尽管这些字符在其他平台上的文件名中有效,但在Windows上,它被解释为目录分隔符(这显然会导致歧义,例如,当有一个文件a\b并且还有一个文件a/b时。

可以说,这是该错误的错误层:只要用户从不签出名称中包含反斜杠的文件,那么一开始就不会有任何问题。

因此,让我们放宽要求:现在,我们仅在树条目中保留其文件名中带有反斜杠的树条目,但我们确实要求添加到Git索引的任何条目在Windows上均不包含反斜杠。

注意:和以前一样,检查由core.protectNTFS保护(以允许通过切换配置设置来覆盖检查),并且在Windows上执行_only _,因为反斜杠不是目录分隔符,即使在写入NTFS格式的卷时也是如此。

另一种方法是尝试防止在文件名中创建带有反斜杠的文件。但是,这会带来一系列问题。
例如,git config -f C:\ProgramData\Git\config ...是指定自定义配置位置的一种非常有效的方法,显然我们_not _是想避免这种情况。
因此,此补丁中选择的方法似乎更好。

此地址为git-for-windows/git issue 2435

(在Saurabh P Bhandarianswer中提到的问题)

答案 2 :(得分:1)

我已经解决了问题(目前),方法是降级到Windows 2.23.0的Git。 该问题在最新版本上仍然存在,并且可以在我的桌面上重现。