我如何查看我所做的任何尚未推送到远程存储库的本地提交?有时,git状态会显示我的分支是在origin/master之前提交的X,但并不总是这样。

这是我安装Git的bug,还是我遗漏了什么?


当前回答

git cherry -v 

摘自:Git:查看所有未推送的提交或不在其他分支中的提交。

其他回答

我使用以下别名仅获取已提交但尚未推送(针对当前分支)的文件列表(以及状态)

git config --global alias.unpushed \
"diff origin/$(git name-rev --name-only HEAD)..HEAD --name-status"

那么只需执行以下操作:

git unpushed

要轻松列出所有分支中的所有未推送提交,可以使用以下命令:

 git log --branches  @{u}..

如果你有git子模块。。。

无论您是使用gitcherry-v还是gitlogs@{u}-p、 不要忘记通过git子模块foreach--递归“gitlogs@{u}..”。

我使用以下bash脚本来检查所有这些:

    unpushedCommitsCmd="git log @{u}.."; # Source: https://stackoverflow.com/a/8182309

    # check if there are unpushed changes
    if [ -n "$($getGitUnpushedCommits)" ]; then # Check Source: https://stackoverflow.com/a/12137501
        echo "You have unpushed changes.  Push them first!"
        $getGitUnpushedCommits;
        exit 2
    fi

    unpushedInSubmodules="git submodule foreach --recursive --quiet ${unpushedCommitsCmd}"; # Source: https://stackoverflow.com/a/24548122
    # check if there are unpushed changes in submodules
    if [ -n "$($unpushedInSubmodules)" ]; then
        echo "You have unpushed changes in submodules.  Push them first!"
        git submodule foreach --recursive ${unpushedCommitsCmd} # not "--quiet" this time, to display details
        exit 2
    fi
git cherry -v

这将列出您的本地评论历史记录(尚未推送)以及相应的消息

有一个名为unpushed的工具,它扫描指定工作目录中的所有Git、Mercurial和Subversion repo,并显示未提交文件和未提交提交的列表。在Linux下安装很简单:

$ easy_install --user unpushed

or

$ sudo easy_install unpushed

以在系统范围内安装。

用法也很简单:

$ unpushed ~/workspace
* /home/nailgun/workspace/unpushed uncommitted (Git)
* /home/nailgun/workspace/unpushed:master unpushed (Git)
* /home/nailgun/workspace/python:new-syntax unpushed (Git)

有关详细信息,请参阅未推送的帮助或官方说明。它还有一个cronjob脚本unpushed notify,用于在屏幕上通知未提交和未推送的更改。