[英]Git: How to get a listing of all untracked files, ignoring untracked submodules?
In a script, I want to check whether a Git repository is clean or not.在脚本中,我想检查 Git 存储库是否干净。 In case it's not clean, changes should be stashed away.
如果它不干净,更改应该被藏起来。 For the check, I'm using:
对于检查,我正在使用:
git diff-index HEAD --
to figure out modifications of tracked files and:找出跟踪文件的修改和:
git ls-files --others
to figure out whether untracked files are present.以确定是否存在未跟踪的文件。 Unfortunately,
git ls-files --others
will also report untracked submodules which can't be stashed away.不幸的是,
git ls-files --others
也会报告无法隐藏的未跟踪子模块。
Is there some option or a different Git command which returns the same result as git ls-files --other
except of untracked submodules ?是否有一些选项或不同的 Git 命令返回与
git ls-files --other
相同的结果,除了未跟踪的子模块?
git
cannot see whether an untracked directory is supposed to become a submodule or not. git
无法查看未跟踪的目录是否应该成为子模块。 It is just an untracked directory.它只是一个未跟踪的目录。
You might check for a .git
subdirectory to check if that untracked directory is in fact a git
repository;您可能会检查
.git
子目录以检查未跟踪的目录是否实际上是git
存储库; something like:就像是:
for untracked in $(git ls-files --others)
do
if [ ! -e $untracked/.git ]
then
echo $untracked
fi
done
which would print the untracked files/directories that are not a git repository.这将打印不是 git 存储库的未跟踪文件/目录。
you can set it up as a git alias like this:您可以将其设置为 git 别名,如下所示:
git config --global alias.untracked-not-repo '!'"bash -c 'for untracked in \$(git ls-files --others); do if [ ! -e \$untracked/.git ]; then echo \$untracked; fi; done'"
now you can use it like现在你可以像这样使用它
git untracked-not-repo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.