说到GIT,我完全是个菜鸟。在过去的几天里,我只是迈出了我的第一步。我在我的笔记本电脑上设置了一个回购,从一个SVN项目中拉下Trunk(在分支上有一些问题,没有让它们工作),但一切似乎都很好。
现在我希望能够从笔记本电脑拉或推到我的主桌面。原因是笔记本电脑在火车上很方便,因为我每天要花2个小时在路上,可以完成一些好的工作。但我家里的主要机器对发展很有帮助。所以当我回到家时,我希望能够从笔记本电脑推/拉到主电脑。我认为最简单的方法是在局域网内共享代码文件夹,并这样做:
git clone file://192.168.10.51/code
不幸的是,这似乎对我不起作用:
所以我打开一个git bash cmd并输入上面的命令,我在C:\code(两台机器的共享文件夹),这是我得到的结果:
Initialized empty Git repository in C:/code/code/.git/
fatal: 'C:/Program Files (x86)/Git/code' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
如何以最简单的方式在两台机器之间共享存储库。
还会有其他地方作为正式的存储点,其他开发人员和CI服务器等将从这些地方提取,这只是为了让我可以在两台机器上进行相同的回购。
根据Sebastian的建议,我得到了以下信息:
C:\code>git clone --no-hardlinks file://192.168.10.51/code
Initialized empty Git repository in C:/code/code/.git/
fatal: 'C:/Program Files (x86)/Git/code' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
**编辑-回答**
感谢所有的帮助。我尝试映射一个驱动器,所以我认为我会回去,重试没有映射。最后的结果是:
git clone file://\\\\192.168.0.51\code
这很有效。
谢谢
不确定是因为我的git版本(1.7.2)或其他原因,但上面列出的使用机器名和IP选项的方法对我不起作用。另外一个可能重要也可能不重要的细节是,这个回购是一个我已经初始化并从另一台机器推到的裸回购。
我试图克隆project1如上所述,使用如下命令:
$ git clone file:////<IP_ADDRESS>/home/user/git/project1
Cloning into project1...
fatal: '//<IP_ADDRESS>/home/user/git/project1' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
and
$ git clone file:////<MACHINE_NAME>/home/user/git/project1
Cloning into project1...
fatal: '//<MACHINE_NAME>/home/user/git/project1' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
对我有用的是一些更简单的方法:
$ git clone ../git/project1
Cloning into project1...
done.
注意-即使被克隆的repo是裸露的,这确实产生了一个“正常”的克隆,所有实际的代码/图像/资源文件,我希望(而不是git repo的内部)。
虽然从Git 2.21(2019年2月,见下文)开始支持UNC路径,但Git 2.24(2019年第四季度)将允许
git clone file://192.168.10.51/code
没有更多的file:////xxx, 'file://'就足够引用UNC路径共享了。
参见“Git Fetch Error with UNC”。
注意,从2016年开始,和Windows Git打包的MingW-64 Git .exe,支持UNC路径。
(参见“msys、msys2和MinGW-64之间有什么关系?”)
在Git 2.21(2019年2月)中,这种支持甚至可以在msys2 shell中扩展(在UNC路径周围加上引号)。
参见Johannes Schindelin (dscho)的commit 9e9da23, commit 5440df4(2019年1月17日)。
资助人:Kim Gybels (Jeff-G)
(由Junio C Hamano—gitster—在commit f5dd919中合并,2019年2月5日)
在Git 2.21之前,由于Git生成Git -upload-pack方法中的一个怪癖,有一个
当传递带有反斜杠的路径时,Git会强制
命令行,在shell中有不同的引用语义
Git for Windows(是一个MSYS2程序)而不是常规的Win32可执行文件
例如git.exe本身。
对象的UNC路径中两个反斜杠的第一个
形式\ \ \ myserver \文件夹存储库。Git被剥离。
现在这个问题得到了缓解:
mingw: special-case arguments to sh
The MSYS2 runtime does its best to emulate the command-line wildcard expansion and de-quoting which would be performed by the calling Unix shell on Unix systems.
Those Unix shell quoting rules differ from the quoting rules applying to Windows' cmd and Powershell, making it a little awkward to quote command-line parameters properly when spawning other processes.
In particular, git.exe passes arguments to subprocesses that are not intended to be interpreted as wildcards, and if they contain backslashes, those are not to be interpreted as escape characters, e.g. when passing Windows paths.
Note: this is only a problem when calling MSYS2 executables, not when calling MINGW executables such as git.exe. However, we do call MSYS2 executables frequently, most notably when setting the use_shell flag in the child_process structure.
There is no elegant way to determine whether the .exe file to be executed is an MSYS2 program or a MINGW one.
But since the use case of passing a command line through the shell is so prevalent, we need to work around this issue at least when executing sh.exe.
Let's introduce an ugly, hard-coded test whether argv[0] is "sh", and
whether it refers to the MSYS2 Bash, to determine whether we need to
quote the arguments differently than usual.
That still does not fix the issue completely, but at least it is something.
Incidentally, this also fixes the problem where git clone \\server\repo failed due to incorrect handling of the backslashes when handing the path to the git-upload-pack process.
Further, we need to take care to quote not only whitespace and backslashes, but also curly brackets.
As aliases frequently go through the MSYS2 Bash, and as aliases frequently get parameters such as HEAD@{yesterday}, this is really important.
看到t / t5580-clone-push-unc.sh