Viewing unpushed Git commits

前端 未结 25 2347
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 09:00

    Here's my portable solution (shell script which works on Windows too without additional install) which shows the differences from origin for all branches: git-fetch-log

    An example output:

    ==== branch [behind 1]
    
    > commit 652b883 (origin/branch)
    | Author: BimbaLaszlo <bimbalaszlo@gmail.com>
    | Date:   2016-03-10 09:11:11 +0100
    |
    |     Commit on remote
    |
    o commit 2304667 (branch)
      Author: BimbaLaszlo <bimbalaszlo@gmail.com>
      Date:   2015-08-28 13:21:13 +0200
    
          Commit on local
    
    ==== master [ahead 1]
    
    < commit 280ccf8 (master)
    | Author: BimbaLaszlo <bimbalaszlo@gmail.com>
    | Date:   2016-03-25 21:42:55 +0100
    |
    |     Commit on local
    |
    o commit 2369465 (origin/master, origin/HEAD)
      Author: BimbaLaszlo <bimbalaszlo@gmail.com>
      Date:   2016-03-10 09:02:52 +0100
    
          Commit on remote
    
    ==== test [ahead 1, behind 1]
    
    < commit 83a3161 (test)
    | Author: BimbaLaszlo <bimbalaszlo@gmail.com>
    | Date:   2016-03-25 22:50:00 +0100
    |
    |     Diverged from remote
    |
    | > commit 4aafec7 (origin/test)
    |/  Author: BimbaLaszlo <bimbalaszlo@gmail.com>
    |   Date:   2016-03-14 10:34:28 +0100
    |
    |       Pushed remote
    |
    o commit 0fccef3
      Author: BimbaLaszlo <bimbalaszlo@gmail.com>
      Date:   2015-09-03 10:33:39 +0200
    
          Last common commit
    

    Parameters passed for log, e.g. --oneline or --patch can be used.

    0 讨论(0)
  • 2020-11-22 09:02

    I suggest you go see the script https://github.com/badele/gitcheck, i have coded this script for check in one pass all your git repositories, and it show who has not commited and who has not pushed/pulled.

    Here a sample result enter image description here

    0 讨论(0)
  • 2020-11-22 09:03

    I use the following alias to get just the list of files (and the status) that have been committed but haven't been pushed (for the current branch)

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

    then just do:

    git unpushed
    
    0 讨论(0)
  • 2020-11-22 09:04

    You can show all commits that you have locally but not upstream with

    git log @{u}..
    

    @{u} or @{upstream} means the upstream branch of the current branch (see git rev-parse --help or git help revisions for details).

    0 讨论(0)
  • 2020-11-22 09:05

    I believe the most typical way of doing this is to run something like:

    git cherry --abbrev=7 -v @{upstream}
    

    However, I personally prefer running:

    git log --graph --decorate --pretty=oneline --abbrev-commit --all @{upstream}^..
    

    which shows the commits from all branches which are not merged upstream, plus the last commit in upstream (which shows up as a root node for all the other commits). I use it so often that I have created alias noup for it.

    git config --global alias.noup \
    'log --graph --decorate --pretty=oneline --abbrev-commit --all @{upstream}^..'
    
    0 讨论(0)
  • 2020-11-22 09:06

    Similar: To view unmerged branches:

    git branch --all --no-merged
    

    Those can be suspect but I recommend the answer by cxreg

    0 讨论(0)
提交回复
热议问题