1. 程式人生 > >Git初學使用記錄fatal: this operation must be run in a work tree解決辦法

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 [email protected] MINGW64 ~/testgit/.git (GIT_DIR!)
$ cd ../
Huang [email protected] MINGW64 ~/testgit (master)
$ git add test.txt
fatal: pathspec 'test.txt' did not match any files

因為之前我們把text.txt新增到.git資料夾中了,所以返回到上個資料夾之後需要重新新增test.txt

Huang [email protected] MINGW64 ~/testgit (master)
$ touch test.txt

Huang [email protected] MINGW64 ~/testgit (master)
$ git add test.txt

Huang [email protected] MINGW64 ~/testgit (master)
$ git status
On branch master

No commits yet

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

        new file:   test.txt

解決了。不知道你遇到的問題跟我一不一樣呢~