Determine if directory is under git control

后端 未结 10 1590
醉酒成梦
醉酒成梦 2021-01-30 12:25

How can I tell if a given directory is part of a git respository?

(The following is in python, but bash or something would be fine.)

os.path.isdir(\'.svn         


        
10条回答
  •  死守一世寂寞
    2021-01-30 12:58

    Just found this in git help rev-parse

    git rev-parse --is-inside-work-tree
    

    prints true if it is in the work tree, false if it's in the '.git' tree, and fatal error if it's neither. Both 'true' and 'false' are printed on stdout with an exit status of 0, the fatal error is printed on stderr with an exit status of 128.

提交回复
热议问题