有没有可以运行的命令来检查是否有提交要推送到origin/master?
git [some command] origin master
会输出类似以下内容:
origin/master is behind by 7 commits
下面有两种方法可以列出不在origin/master上的"额外"提交:
git log --oneline origin/master..HEAD
git rev-list --oneline ^origin/master HEAD
--oneline
只是以较短的格式列出它们。此外,如果您的分支跟踪原点/主节点,则会显示一个简单的git status
。
git diff --stat master origin/master
示例输出:
classes/Mammoth/Article.php | 12 ++++++++++--
classes/Mammoth/Article/Admin/Section/Controller.php | 34 +++++++++++++++++-----------------
classes/Mammoth/Article/Filter.php | 14 +++++++-------
classes/Mammoth/Article/Section.php | 18 ++++++++++--------
classes/Mammoth/Article/Section/IMySQL.php | 2 +-
migrations/20130411111424_ChangeNameToURIOnSectionsTable.php | 14 --------------
migrations/sql/up/20130411111424_ChangeNameToURIOnSectionsTable.sql | 5 -----
solr-core/conf/schema.xml | 2 +-
views/admin/section/form.php | 8 ++++----
views/admin/section/view.php | 10 +++++-----
10 files changed, 55 insertions(+), 64 deletions(-)
如果你的抓取是最新的(这里的所有其他答案都认为是这样(
$ git checkout
Your branch is ahead of 'origin/master' by 9 commits.
(use "git push" to publish your local commits)
为了获得所有分支机构的信息,
$ git branch -avvv
我解决这个问题的第一次尝试是这样的:
git push --all -n 2>&1 | grep -q 'Everything up-to-date' ||
echo "Outstanding commits to be pushed at $PWD"
它并不健壮,因为它会声称有未完成的错误提交。最大的问题是,如果试图通过https链接推送到github repo,它会要求提供用户名/密码(通常是因为我在一些不应该直接推送更改的repo上进行了RO结账(。
jtill的答案似乎最适合我,因为它包含了如何检查所有分支的说明。因此,我的第二次尝试看起来是这样的:
git branch -avvv 2>&1 | grep -q ': ahead ' &&
echo "Outstanding commits to be pushed at $PWD"
然而,这也至少有一个警告——如果提交消息包含字符串":ahead",则会出现误报。
所以我有这个命令"检查所有git repos的状态":
for gitrepo in $(find ~ -name '.git')
do
cd $(dirname $gitrepo)
git fetch >/dev/null 2>&1 ||
echo "Git fetch failed at $PWD"
git branch -avvv 2>&1 | grep -q ': ahead ' &&
echo "Outstanding commits to be pushed at $PWD"
done
:-(
这并不是你想要的,因为它在寻找相同的东西"git状态";显示为更改。但当我搜索这些信息时,谷歌把你的帖子提了出来。
这个linux的小shell脚本会告诉你是否有什么变化,但前提是它还没有提交。
if [[ "$(git status --porcelain)" != "" ]]; then
echo "there are changes that should be committed and pushed"
fi
对于提交的更改,接受的答案适用于主分支,或者如果您知道您关心的分支名称。这将适用于当前分支中的提交,并显示提交的计数:
git log --oneline origin..HEAD | wc -l
输出可能是:
2