Viewing unpushed Git commits

前端 未结 25 2344
Happy的楠姐
Happy的楠姐 2020-11-22 08:05

How can I view any local commits I\'ve made, that haven\'t yet been pushed to the remote repository? Occasionally, git status will print out that my branch is X

相关标签:
25条回答
  • 2020-11-22 08:40

    If the number of commits that have not been pushed out is a single-digit number, which it often is, the easiest way is:

    $ git checkout
    

    git responds by telling you that you are "ahead N commits" relative your origin. So now just keep that number in mind when viewing logs. If you're "ahead by 3 commits", the top 3 commits in the history are still private.

    0 讨论(0)
  • 2020-11-22 08:41
    git diff origin
    

    Assuming your branch is set up to track the origin, then that should show you the differences.

    git log origin
    

    Will give you a summary of the commits.

    0 讨论(0)
  • 2020-11-22 08:42

    All the other answers talk about "upstream" (the branch you pull from).
    But a local branch can push to a different branch than the one it pulls from.

    master might not push to the remote tracking branch "origin/master".
    The upstream branch for master might be origin/master, but it could push to the remote tracking branch origin/xxx or even anotherUpstreamRepo/yyy.
    Those are set by branch.*.pushremote for the current branch along with the global remote.pushDefault value.

    It is that remote-tracking branch which counts when seeking unpushed commits: the one that tracks the branch at the remote where the local branch would be pushed to.
    The branch at the remote can be, again, origin/xxx or even anotherUpstreamRepo/yyy.

    Git 2.5+ (Q2 2015) introduces a new shortcut for that: <branch>@{push}

    See commit 29bc885, commit 3dbe9db, commit adfe5d0, commit 48c5847, commit a1ad0eb, commit e291c75, commit 979cb24, commit 1ca41a1, commit 3a429d0, commit a9f9f8c, commit 8770e6f, commit da66b27, commit f052154, commit 9e3751d, commit ee2499f [all from 21 May 2015], and commit e41bf35 [01 May 2015] by Jeff King (peff).
    (Merged by Junio C Hamano -- gitster -- in commit c4a8354, 05 Jun 2015)

    Commit adfe5d0 explains:

    sha1_name: implement @{push} shorthand

    In a triangular workflow, each branch may have two distinct points of interest: the @{upstream} that you normally pull from, and the destination that you normally push to. There isn't a shorthand for the latter, but it's useful to have.

    For instance, you may want to know which commits you haven't pushed yet:

    git log @{push}..
    

    Or as a more complicated example, imagine that you normally pull changes from origin/master (which you set as your @{upstream}), and push changes to your own personal fork (e.g., as myfork/topic).
    You may push to your fork from multiple machines, requiring you to integrate the changes from the push destination, rather than upstream.
    With this patch, you can just do:

    git rebase @{push}
    

    rather than typing out the full name.

    Commit 29bc885 adds:

    for-each-ref: accept "%(push)" format

    Just as we have "%(upstream)" to report the "@{upstream}" for each ref, this patch adds "%(push)" to match "@{push}".
    It supports the same tracking format modifiers as upstream (because you may want to know, for example, which branches have commits to push).

    If you want to see how many commit your local branches are ahead/behind compared to the branch you are pushing to:

    git for-each-ref --format="%(refname:short) %(push:track)" refs/heads
    
    0 讨论(0)
  • 2020-11-22 08:42

    You could try....

    gitk
    

    I know it is not a pure command line option but if you have it installed and are on a GUI system it's a great way to see exactly what you are looking for plus a whole lot more.

    (I'm actually kind of surprised no one mentioned it so far.)

    0 讨论(0)
  • 2020-11-22 08:42

    There is tool named unpushed that scans all Git, Mercurial and Subversion repos in specified working directory and shows list of ucommited files and unpushed commits. Installation is simple under Linux:

    $ easy_install --user unpushed
    

    or

    $ sudo easy_install unpushed
    

    to install system-wide.

    Usage is simple too:

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

    See unpushed --help or official description for more information. It also has a cronjob script unpushed-notify for on-screen notification of uncommited and unpushed changes.

    0 讨论(0)
  • 2020-11-22 08:46

    If you want to see all commits on all branches that aren't pushed yet, you might be looking for something like this:

    git log --branches --not --remotes
    

    And if you only want to see the most recent commit on each branch, and the branch names, this:

    git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
    
    0 讨论(0)
提交回复
热议问题