Git初学使用记录fatal: this operation must be run in a work tree解决办法

fatal: this operation must be run in a work tree

$ git add test.txt
fatal: this operation must be run in a work tree

解决办法

原因是我们把text.txt添加到.git文件夹中了,所以返回上个文件夹

Huang Rong@DESKTOP-O2VRRQO MINGW64 ~/testgit/.git (GIT_DIR!)
$ cd ../
Huang Rong@DESKTOP-O2VRRQO MINGW64 ~/testgit (master)
$ git add test.txt
fatal: pathspec 'test.txt' did not match any files

因为之前我们把text.txt添加到.git文件夹中了,所以返回到上个文件夹之后需要重新添加test.txt

Huang Rong@DESKTOP-O2VRRQO MINGW64 ~/testgit (master)
$ touch test.txt

Huang Rong@DESKTOP-O2VRRQO MINGW64 ~/testgit (master)
$ git add test.txt

Huang Rong@DESKTOP-O2VRRQO MINGW64 ~/testgit (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached ..." to unstage)

        new file:   test.txt

解决了。不知道你遇到的问题跟我一不一样呢~

你可能感兴趣的:(错误记录,Git,Git)