Search code examples
gitgit-commitgit-log

How to view git commits when local branch is ahead of origin Commits


I want to view git commits when my branch is ahead of origin branch.

i tried git log it returns all commits. but, i want to view only ahead commits from branch to origin/branch

here what i mean,

On branch permissions
Your branch is ahead of 'upstream/permissions' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

in this case i want to view 2 commits


Solution

  • When you run log, you can tell it one or more commits whose history you want to include, and also one or more commits whose history you want to exclude. (When you don't specify, git assumes you mean "the history of the commit I have currently checked out.)

    In your case, you want the history of permissions (the local branch you're on), but you want to exclude the history of upstream/permissions (the remote reference that tells you where the origin remote's copy of the permissions branch was, when last you talked to origin.

    So one option would be

    git log permissions ^upstream/permissions
    

    There are shorthand notations for this, like

    git log upstream/permissions..permissions