检查当前目录是否为Git存储库 [英] Check if current directory is a Git repository
本文介绍了检查当前目录是否为Git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查当前目录是否为Git存储库? (当我不在Git仓库中时,我不想执行一堆命令并获得一堆致命的:不是git仓库
响应)。
解决方案
从bash完成文件中复制以下内容是一种天真的做法
#Copyright(C)2006,2007 Shawn O. Pearce< spearce@spearce.org>
#概念上基于gitcompletion(http://gitweb.hawaga.org.uk/)。
#在GNU通用公共许可证2.0版下发布。
if [-d .git];然后
echo .git;
else
git rev-parse --git-dir 2>的/ dev / null的;
fi;
您可以将它封装在函数中,或者在脚本中使用它。
压缩成适用于bash或zsh的单行条件
[-d .git] || git rev-parse --git-dir> / dev / null 2>& 1
I am writing a series of scripts for Git management in zsh.
How do I check if the current directory is a Git repository? (When I'm not in a Git repo, I don't want to execute a bunch of commands and get a bunch of fatal: Not a git repository
responses).
解决方案
Copied from the bash completion file the following is a naive way to do it
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
if [ -d .git ]; then
echo .git;
else
git rev-parse --git-dir 2> /dev/null;
fi;
You could either wrap that in a function or use it in a script.
Condensed into a one line condition suitable for bash or zsh
[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1
这篇关于检查当前目录是否为Git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文