git subtree split error: You need to run this command from the toplevel of the working tree

git subtree split error: You need to run this command from the toplevel of the working tree

我在 /srv/git/mysite.git 中有一个 git 存储库。

工作目录设置为

/srv/www/mysite

在 git /srv/git/mysite.git/config:

[core] repositoryformatversion = 0
filemode = false
bare = false
worktree = /srv/www/mysite

[receive] denyCurrentBranch = updateInstead

我想用子树拆分目录内容:

/srv/www/mysite/mysubsite

分支我的子站点。

当我执行时:

cd /srv/git/mysite.git
git subtree split --prefix=mysubsite -b mysubsite

我收到错误

You need to run this command from the toplevel of the working tree.

这个帖子似乎有关于我的问题的相关信息: http://git.661346.n2.nabble.com/git-users-Problem-using-detached-worktrees-with-commands-implemented-in-scripts-td7597786.html

我尝试了以下方法:

export GIT_WORK_TREE=/srv/www/mysite

export GIT_DIR=/srv/git/mysite.git

cd /srv/www/mysite

git subtree split --prefix=mysubsite -b mysubsite

我又报错了:

You need to run this command from the toplevel of the working tree.

我该如何解决这个问题?

适合我,export GIT_DIR 就足够了。

$ git --version 
git version 2.11.0

这也有效:

$ cd /srv/www/mysite
$ git --git-dir=/srv/git/mysite.git subtree split --prefix=mysubsite -b mysubsite