6

有没有可以运行的命令来检查是否有任何提交推送到源/主?

git [some command] origin master

会输出类似:

origin/master is behind by 7 commits
4

4 回答 4

9

以下是列出您拥有的不在 origin/master 上的“额外”提交的两种方法:

git log --oneline origin/master..HEAD
git rev-list --oneline ^origin/master HEAD

只是以较短的--oneline格式列出它们。此外,如果您的分支跟踪 origin/master,git status则会向您显示一个简单的。

于 2013-04-11T02:31:19.380 回答
3
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(-)
于 2013-04-11T02:28:34.910 回答
3

如果您了解最新信息(这里的所有其他答案也都假定)

$ git checkout
Your branch is ahead of 'origin/master' by 9 commits.
  (use "git push" to publish your local commits)

要获取所有分支机构的信息,

$ git branch -avvv
于 2013-04-11T03:12:43.443 回答
0

我第一次尝试解决这个问题是这样的:

git push --all -n 2>&1 | grep -q 'Everything up-to-date' || 
echo "Outstanding commits to be pushed at $PWD"

It's not robust, as it will claim there are outstanding commits on errors. The biggest problem is that it will ask for username/password i.e. if attempting to push to a github repo with https-link (typically because I did a RO checkout on some repo where I'm not supposed to directly push changes).

The jtill answer seems to fit me the best, as it contains instructions on how to check this for all branches. Hence my second attempt looks like this:

 git branch -avvv 2>&1 | grep -q ': ahead ' && 
   echo "Outstanding commits to be pushed at $PWD"

However, this also have at least one caveat - there will be false positives if a commit message contains the string ': ahead '.

So then I have this command for "check the status of all the 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

:-)

于 2015-06-24T10:18:19.003 回答