添加到“git status --porcelain”的内容使其表现得像“git status”? [英] What to add to "git status --porcelain" to make it behave like "git status"?
问题描述
导致了一些关于如何检查Git仓库是否包含脏索引或未跟踪文件的想法。我从该讨论中获得的答案如下:
$ b
#!/ bin / sh
exit $(git status --porcelain | wc -l)
这个答案背后的想法是来模拟程序员会做的事情:运行 git status
,然后检查输出。
不幸的是 git status --polcelain
和 git status
不要做完全相同的事情。特别是, git status
会报告未修改的更改,而 git status --porcelain
不会。以下是一个例子:
pre $ [jarmo @ localhost math-hl] $ git status --porcelain
[jarmo @ localhost math-hl] $ git status
#在分支master上
#你的分支在1次提交之前在'origin / master'前面。
#(使用git push发布你的本地提交)
#
没有提交,工作目录干净
所以我的问题是:我需要添加到原始脚本以确定何时回购没有改变?特别是,这是否是一种正确的方法?
$ b
#!/ bin / bash $ b $如果[$(git status --porcelain | wc -l)!=0\
-o $(git log @ {u} .. | wc -l)!=0];那么
回声本地回购不干净
运行,依靠 git log
,或者我应该使用plumbing命令吗?
注意:使用 git status --porcelain / GIT中/提交/ 7a76c28ff29d6f819bb0bf9852b858f974b5c53a相对= nofollow noreferrer>提交7a76c28 - 用于GIT中1.9.2(2014年4月)中,由马修莫伊莫埃
)
禁用翻译 - 使用--porcelain
git status --branch --porcelain
显示分支
的状态(前进,后退,消失),并使用gettext
转换字符串。
当使用
- 瓷器
时使用硬编码字符串,但保留gettext
翻译为git status --short
,这实质上是相同的,但
意味着可以被人读取。
这意味着 git status --porcelain 继续显示与
git status
不同的结果,这次是因为缺乏翻译。
但是现在的输出总是一样的(独立于用于翻译的LOCALE,因为所述翻译现在由 - 瓷器
选项停用)。
和
git status --porcelain
应该给出稳定的输出,但是
请参阅提交b9e2bc5 (2017年3月14日)由迈克尔Ĵ格鲁伯( MJG
)。<无线电通信>
(由 Junio C Hamano - gitster $ c $合并提交58e9773 ,2017年3月17日) -
sup>
确保其余两个字符串(初始提交,分离头)
也是稳定的。
An earlier question resulted in some ideas on how to check whether your Git repo contains a dirty index or untracked files. The answer I adopted from that discussion was the following:
#!/bin/sh
exit $(git status --porcelain | wc -l)
The idea behind that answer was to emulate what the programmer would do: run git status
and then examine the output.
Unfortunately git status --porcelain
and git status
do not do exactly the same thing. In particular, git status
will report unpushed changes, while git status --porcelain
will not. Here is an example
[jarmo@localhost math-hl]$ git status --porcelain
[jarmo@localhost math-hl]$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
So my question is: what do I need to add to the original script to also identify when the repo has unpushed changes? In particular, would this be a correct approach?
#!/bin/bash
if [ $(git status --porcelain | wc -l) != "0" \
-o $(git log @{u}.. | wc -l) != "0" ]; then
echo "local repo is not clean"
Would it be ok, in the long run, to rely on git log
, or should I use a "plumbing" command instead?
Note: git status --porcelain
has just been made a bit more reliable with commit 7a76c28, for git 1.9.2 (April 2014), by Matthieu Moy moy
)
disable translation when --porcelain is used
"
git status --branch --porcelain
" displays the status of the branch (ahead, behind, gone), and usedgettext
to translate the string.Use hardcoded strings when
--porcelain
is used, but keep thegettext
translation for "git status --short
" which is essentially the same, but meant to be read by a human.
That means git status --porcelain
keep displaying a different result than git status
, this time because of the lack of translation.
But that output is now always the same (independent of the LOCALE used for the translation, since said translation is now deactivated by the --porcelain
option)
And git status --porcelain
is improved again in Git 2.13 (Q2 2017)
"
git status --porcelain
" is supposed to give a stable output, but a few strings were left as translatable by mistake.
See commit b9e2bc5 (14 Mar 2017) by Michael J Gruber (mjg
).
(Merged by Junio C Hamano -- gitster
-- in commit 58e9773, 17 Mar 2017)
Make sure that the remaining two strings (initial commit, detached head) are stable, too.
这篇关于添加到“git status --porcelain”的内容使其表现得像“git status”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!