Determine if directory is under git control

后端 未结 10 1396
醉酒成梦
醉酒成梦 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:56

    From git help rev-parse again, I think you can do something like :

    git rev-parse --resolve-git-dir  
    

    and check if the command returns the directory path itself. According to the manual git rev-parse returns the path to the directory if the argument contains a git repo or is a file which contains the path to a git repo.

提交回复
热议问题