Why am I getting the message, “fatal: This operation must be run in a work tree?”

前端 未结 15 783
野趣味
野趣味 2020-11-27 12:33

Just installed git on Windows. I set the GIT_DIR variable to be c:\\git\\ and verified that this environment variable is maintained by cygwin (i.e. echo $GIT_DIR is what it

15条回答
  •  有刺的猬
    2020-11-27 13:13

    Explicitly setting the GIT_DIR environment variable forces git to use the given directory as the git repository. It is never needed during normal use.

    In your example, because have specified a GIT_DIR and it isn't named .git (the leading dot is important) and you haven't provided a --work-tree option or set the GIT_WORK_TREE environment variable, that you want a bare repository when you said git init.

    Because a bare repository has no working tree a large selection of commands don't make sense with a bare repository. git add is just one.

    Is there a particular reason that you need to use a non-standard location for your git repository, rather than in a .git subfolder under the working tree root? While it's possible to arrange this it tends to be more work and more liable to user mistakes.

提交回复
热议问题