When pushing branches and tags, get error: cannot spawn git: no such file or directory

感情迁移 提交于 2019-12-10 15:27:08

问题


I have an existing, bare, Git repository created from importing our source and history from CVS. I make a mirror, using:

git clone --mirror git://aserver.adomain.com/myrepo

Then, I want to push all branches and tags to our internal Git repo host, but the push doesn't seem to see the bare repository as a Git repo.

I have tried the following:

git clone --mirror git://aserver.adomain.com/myrepo
git remote set-url origin http://user@anotherserver.adomain.com/project/myrepo.git
git push origin

which results in:

$ git push origin
Password for 'xxxx':
error: cannot spawn git: No such file or directory

or I try:

$ git remote rm origin
Note: Some branches outside the refs/remotes/ hierarchy were not removed;
to delete them, use:
  ...a whole lot of branches...

user@SOMEMACHINE /some/path/myrepo.git (BARE:master)
$ ls
HEAD  config  description  hooks  info  objects  packed-refs  refs

user@SOMEMACHINE /some/path/myrepo.git (BARE:master)
$ git branch -a
  ...a whole lot of local branches...

user@SOMEMACHINE /some/path/myrepo.git (BARE:master)
$ git remote add mygithost http://user@anotherserver.adomain.com/project/myrepo.git

user@SOMEMACHINE /some/path/myrepo.git (BARE:master)
$ git push --all mygithost
Password for 'xxxx':
error: cannot spawn git: No such file or directory

What is the meaning of "cannot spawn git"?

How can I push a bare repo, with all branches, to an empty existing one?

I have googled several possibilities and reviewed several SO issues, but I don't see a solution to this problem. Clearly, my understanding of this process is flawed.

Update

I guess my understanding was not flawed. The error somehow misled me to think that there was something wrong with the bare repository, as I could clone and push branch by branch just fine from "regular" clones.

As it turns out, this is a bug in MSysGit. I moved to Linux because retaining all of the history was a requirement, in my case. I couldn't simply remove branches and tags, as these needed to be pushed to the empty remote repo. So, the following did work:

$ git remote rm origin
$ git clone --mirror git://aserver.adomain.com/myrepo
$ cd /some/path/myrepo.git
$ git remote add mygithost http://user@anotherserver.adomain.com/project/myrepo.git
$ git push --all mygithost
$ git push --tags mygithost

回答1:


As this comment led to a solution (see edit at end of question), here it is reposted as an answer:

Are you using MSysGit? This has been known to happen if you have a large number of tags. See This post.




回答2:


According to this post, the underlying issue is that git misbehaves if installed to a directory with spaces in the path. That's consistent with my environment where I encountered the error and with the error message reported.

I guess that behavior comes as no surprise given that git was originally written by the author of Linux. The typical workaround seems to be to use an operating system that's hostile to spaces in path names.




回答3:


I also has this problem due to a large number of tags when using git on Windows. I solved it by making a batch script that pushed some of the tags one at a time until the number of tags was a bit below 500. Then I was able to make a git push that took some time to complete, but worked.

So you pretty much just open notepad, write git push origin <yourtagname> for each tag you want to push, one per line, save it as blabla.bat in your git repository folder and run it. It is even easier if you just copy all the file names from the tag folder .git\refs\tags and do some replacement magic to add git push origin in front of each file name.




回答4:


I faced the same problem ( cannot spawn git: no such file or directory ) when tried to push on stash/bitbucket git server some large project exported from TFS (on local pc git folder). There was a single branch and a lot of tags (3K+ tags). The problem appears on pushing all tags command, while pushing a single tag works ok. I am using GitExtensions (msysgit based) and connection to remote was http.

The solution was wound suddenly: I re-configured my git to use SSH connection to remote instead of http and this miraculously solve the problem: pushing all tags went successful.



来源:https://stackoverflow.com/questions/14867232/when-pushing-branches-and-tags-get-error-cannot-spawn-git-no-such-file-or-dir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!