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

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


当前回答

你可以试试。。。。

gitk

我知道这不是一个纯粹的命令行选项,但如果你已经安装了它,并且在GUI系统上,这是一个很好的方法,可以准确地看到你想要的东西,还有更多。

(事实上,我有点惊讶,到目前为止没有人提到它。)

其他回答

在当前分支中查找未推送提交的便捷数字别名:

alias unpushed = !GIT_CURRENT_BRANCH=$(git name-rev --name-only HEAD) && git log origin/$GIT_CURRENT_BRANCH..$GIT_CURRENT_BRANCH --oneline

它的基本作用是:

git log origin/branch..branch

而且还确定当前分支名称。

显示本地但非上游的所有提交:

git log @{u}..

@{u} 或@{upstream}表示当前分支的上游分支(有关详细信息,请参阅git-rev-parse-help或git-help修订版)。

如果你有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 diff origin

假设您的分支被设置为跟踪原点,那么这应该会向您显示差异。

git log origin

将向您提供提交的摘要。

类似:要查看未合并的分支,请执行以下操作:

git branch --all --no-merged

这些可能是可疑的,但我建议cxreg给出答案