How to tell if a file is git tracked (by shell exit code)?

后端 未结 8 2134
刺人心
刺人心 2020-11-28 17:24

Is there a way to tell if a file is being tracked by running some git command and checking its exit code?

In other words: is git tracking a file?

8条回答
  •  攒了一身酷
    2020-11-28 18:04

    Try running git status on the file. It will print an error if it's not tracked by git

    PS$> git status foo.txt
    error: pathspec 'foo.txt' did not match any file(s) known to git.
    

提交回复
热议问题