成功从Cygwin Bash克隆后,本地Git存储库不存在

3
当我克隆到通过绝对路径引用的目录(该目录不存在)时,git不会抱怨任何东西,报告0退出代码,但创建该目录。当我重试时,git会编译存在目录:
user@host /tmp
$ git clone https://github.com/zandev/shunit2.git /tmp/shunit01
Cloning into '/tmp/shunit01'...
remote: Counting objects: 1219, done.
emote: Total 1219 (delta 0), reused 0 (delta 0), pack-reused 1219
Receiving objects: 100% (1219/1219), 308.20 KiB | 0 bytes/s, done.
Resolving deltas: 100% (657/657), done.
Checking connectivity... done.

user@host /tmp
$ echo $?
0

user@host /tmp
$ ls /tmp/shunit01
ls: cannot access /tmp/shunit01: No such file or directory

user@host /tmp
$ git clone https://github.com/zandev/shunit2.git /tmp/shunit01
fatal: destination path '/tmp/shunit01' already exists and is not an empty directory.

user@host /tmp
$ echo $?
128

从cygwin、powershell或Windows UI检查时,目录似乎不存在。我没有看到任何错误的迹象。管理员账户也存在相同的问题。
当使用非绝对路径(shunit02或甚至../tmp/shunit02)时,我可以正确克隆该repo。
所用系统环境如下:
  • Windows 7企业版Ver 6.1 Build 7601 Service Pack 1
  • git 2.5.1.windows.1
  • cygwin 2.3.1-1
编辑:

Windows将/tmp目录视为C:\cygwin64\tmp。我使用/tmp作为示例,实际上在/cygdrive/c中也会发生相同的情况。

编辑2:

我正在使用Git for Windows。当使用windows路径作为目标路径时,克隆操作可以正常执行,例如:git clone https://github.com/zandev/shunit2.git 'C:\cygwin64\tmp\shunit4'


请问一下/tmp文件夹的权限是什么?此外,tmp文件夹的绝对路径是什么(即cygpath -w -p /tmp的输出是什么,或者如果您执行cd /tmp && explorer .,哪个文件夹会打开?) - Ashutosh Jindal
2个回答

4

这是由于Git for Windows不接受cygwin路径,因此/a/b/c被翻译为c:\a\b\c。实际上,仓库是被克隆到这个位置的,这解释了为什么后续的克隆尝试会失败。该目录确实存在,但真正的目标却出人意料。

哪些方法可行?

  • 使用与Git for Windows一起提供的bash和其路径约定,
  • 使用可接受cygwin路径的cygwin git(据说可能会有其他问题),
  • 使用本地Windows路径:git clone https://github.com/zandev/shunit2.git 'C:\cygwin64\tmp\shunit4'
  • 使用相对目标名称,似乎可以无问题工作。

为什么这些人不对所有现有操作系统的版本进行文件夹结构全球化!对于开发人员来说,这真的是非常令人畏惧的 :( - Indrajeet Gour

1
请尝试按照http://cs.nyu.edu/~yap/prog/cygwin/FAQs.html#tmpfiles的描述,将现有的/tmp重命名并在cygwin安装文件夹中重新创建

建议1

问:我安装了cygwin,然后我启动它,它给出以下消息:bash.exe: warning: could not find /tmp, please create! bash: /etc/profile: Invalid argument bash: /.bash_profile: Invalid argument

答:您需要首先创建目录/tmp。假设您的cygwin根目录称为C:/cygwin,则应首先创建目录C:/cygwin/tmp。

建议2

看起来您正在使用Git Bash for Windows的git可执行文件在Cygwin中。也许值得尝试使用Cygwin本身提供的git可执行文件。


我没有观察到问题中提到的任何症状。然而,我已经重新创建了 /tmp 目录,但问题仍然存在。 - Oliver Gondža
1
谢谢,是否值得尝试使用Cygwin提供的git可执行文件而不是msysgit来查看问题是否可以重现? - Ashutosh Jindal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接