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
Git - fatal: Could not get current working directory?
提问by ComputerFellow
When I git clone
from 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 .git
file exists. The server is running a Gitlab instance. I have configured ssh
properly 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 clone
in 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 repo
it's fine, but when the for
gets into the second repo
it fails and gives the above fatal
error.
对于第一个repo
它很好,但是当for
进入第二个时repo
它失败并给出上述fatal
错误。
采纳答案by Dave Morrissey
My guess is that somewhere in your do stuff
section 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。