git 致命:此操作必须在工作树中运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9262801/
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
fatal: This operation must be run in a work tree
提问by Kiran K Telukunta
I get this error when I try to change branch.
当我尝试更改分支时出现此错误。
Probably I will give some information of the commands at
可能我会在以下位置提供一些命令的信息
/path/to/git/repo/.
upon command:
根据命令:
git branch
I get following output
我得到以下输出
* V1.5
V2.0
master
And when I try the command
当我尝试命令时
git checkout V2.0
I get following output:
我得到以下输出:
fatal: This operation must be run in a work tree
config file contents:
配置文件内容:
cat config
[core]
repositoryformatversion = 0
filemode = true
bare = true
[remote "origin"]
url = /path/to/git/repo/.git
回答by Bombe
You repository is bare, i.e. it does not have a working tree attached to it. You can clone it locally to create a working tree for it, or you could use one of several other options to tell Git where the working tree is, e.g. the --work-tree
option for single commands, or the GIT_WORK_TREE
environment variable. There is also the core.worktree
configuration option but it will not work in a bare repository (check the man page for what it does).
您的存储库是空的,即它没有附加的工作树。你可以在本地克隆它来为它创建一个工作树,或者你可以使用其他几个选项之一来告诉 Git 工作树在哪里,例如--work-tree
单个命令的选项或GIT_WORK_TREE
环境变量。还有core.worktree
配置选项,但它不能在裸存储库中工作(查看手册页了解它的作用)。
# git --work-tree=/path/to/work/tree checkout master
# GIT_WORK_TREE=/path/to/work/tree git status