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

2

9

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

Crim answered 30/6, 2017 at 13:11 Comment(0)
S
3

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
Shakedown answered 30/6, 2017 at 14:29 Comment(0)
U
8

Simple,

git log branch...origin/branch

Or little more beautiful :

git log --graph --color --decorate --oneline branch...origin/branch
Unbated answered 30/6, 2017 at 13:14 Comment(5)
can you explain? i tried develop as well replaced with my branch it shows an errorCrim
tried, git log br_name origin/br_name and this too git log develop...origin/developCrim
Use git log br_name...origin/br_name - you are forgetting the .... Besides you don't have develop branch, that's why second command is failing.Unbated
i tried to to but it returns all. brname..origin/brname shows all but origin/brname..brname works fineCrim
i upvote for your graphical representation thanks :) it looks like pycharmCrim
S
3

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
Shakedown answered 30/6, 2017 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.