问题
I have a git repo with a submodule.
I would use in post-receive hook file:
git --git-dir="$GIT_DIR" --work-tree="$GIT_WORKDIR1" submodule update --init --recursive
but I get the following error:
remote: fatal: /usr/libexec/git-core/git-submodule cannot be used without a working tree.
I did not get solution for this problem.
What should I do to make it work?
回答1:
You may see this error if you've renamed the path (working-tree) of a git submodule. In my case I had updated the path in .gitmodules
to match my new path and thought I was good. But when I did a git pull
later it added new files in the old path. This is because there are two places the module path is defined. You need to also update your "working-tree" as defined in the .git/modules/{modulename}/config
file.
There are some great details about the working-tree on this post as well.
回答2:
I got this same error when running git submodule
inside of a shell I spawned while I was running git log
(with the !bash
command). What also confused me was that I could run all git commands if I ran them with sudo, and that this problem affected multiple repos, not only the one I was running git log
into.
The solution of course is to exit the subshell and the git log
command.
回答3:
I also stumbled across this issue and found it is caused, because I needed to cd into the workdir first. I am not sure why this is required, maybe it is a git bug? You can also pass the path via -C
and set the workdir to .
:
git --git-dir="$GIT_DIR" --work-tree=. -C "$GIT_WORKDIR1" submodule update --init --recursive
Also I noticed that in my plesk git user interface (netcup.com) variables do not seems to work, I have to specify absolute paths without variables here:
git --git-dir=/git/repo_name.git --work-tree=. -C /httpdocs/website submodule update --init --recursive
来源:https://stackoverflow.com/questions/48767595/git-error-fatal-usr-libexec-git-core-git-submodule-cannot-be-used-without-a-w