bash Git - 致命:无法获取当前工作目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25138228/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:02:22  来源:igfitidea点击:

Git - fatal: Could not get current working directory?

linuxgitbashunixgitlab

提问by ComputerFellow

When I git clonefrom a repo, I get,

当我git clone从一个回购,我得到,

fatal: Could not get current working directory: No such file or directory

fatal: Could not get current working directory: No such file or directory

What do I do? I have checked the server and found that .gitfile exists. The server is running a Gitlab instance. I have configured sshproperly with the keys, and I've been committing & cloning for a while now without any error, and this happens all of a sudden.

我该怎么办?我检查了服务器,发现该.git文件存在。服务器正在运行 Gitlab 实例。我已经ssh正确配置了密钥,并且我已经提交和克隆了一段时间没有任何错误,这突然发生。

FWIW, I'm doing the git clonein a bash script.

FWIW,我git clone在 bash 脚本中做。



Update

更新

This is my bash script,

这是我的 bash 脚本,

for repo in $repos
do
   git clone $repo /tmp/tmpdir/
   # do stuff with /tmp/tmpdir/
   rm -rf /tmp/tmpdir/
done

for the first repoit's fine, but when the forgets into the second repoit fails and gives the above fatalerror.

对于第一个repo它很好,但是当for进入第二个时repo它失败并给出上述fatal错误。

采纳答案by Dave Morrissey

My guess is that somewhere in your do stuffsection you change directory into /tmp/tmpdir/so that in the next loop, the current working directory no longer exists. The fix is to change directory to /tmp/(or anywhere really) before removing the /tmp/tmdir/directory.

我的猜测是在您的do stuff部分中的某个地方将目录更改为,/tmp/tmpdir/以便在下一个循环中,当前工作目录不再存在。解决方法是/tmp/在删除/tmp/tmdir/目录之前将目录更改为(或任何地方)。

回答by thebiggestlebowski

In my case, this was caused by issuing a "git clone" from a subdirectory of a local git repo. I had to cd to another directory before I could clone the new repo.

就我而言,这是由于从本地 git 存储库的子目录发出“git clone”造成的。我必须先 cd 到另一个目录,然后才能克隆新的 repo。