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

前端 未结 15 884
野趣味
野趣味 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:15

    The direct reason for the error is that yes, it's impossible to use git-add with a bare repository. A bare repository, by definition, has no work tree. git-add takes files from the work tree and adds them to the index, in preparation for committing.

    You may need to put a bit of thought into your setup here, though. GIT_DIR is the repository directory used for all git commands. Are you really trying to create a single repository for everything you track, maybe things all over your system? A git repository by nature tracks the contents of a single directory. You'll need to set GIT_WORK_TREE to a path containing everything you want to track, and then you'll need a .gitignore to block out everything you're not interested in tracking.

    Maybe you're trying to create a repository which will track just c:\www? Then you should put it in c:\www (don't set GIT_DIR). This is the normal usage of git, with the repository in the .git directory of the top-level directory of your "module".

    Unless you have a really good reason, I'd recommend sticking with the way git likes to work. If you have several things to track, you probably want several repositories!

提交回复
热议问题