2

When you do a Pull Request in Github or Stash you get a list of the commit from your current branch.

What would be the git command to get a list of the commit which makes up the current branch without specifying the name of the branch which we started from?

Laurent Kempé
  • 731
  • 10
  • 21

3 Answers3

1

In git it's not possible to only list commits for a specific branch without specifying references you want to exclude.

But you could determine the references programatically, such a command could look like this:

git log HEAD $(git branch -a | grep -v "^*" | grep -v "\->" | sed "s/^ /--not /")

For easier usage you could define an alias:

git config --global alias.branchlog '!git log HEAD $(git branch -a | grep -v "^*" | grep -v "\->" | sed "s/^ /--not /")'

And then just use it by typing git branchlog.

Note: If you want to ignore remote branches, you have to remove the -a option from the git branch -a call.


This command will log all commits which are ONLY reachable from the current HEAD. It achieves this by listing all branches (git branch -a), removing the current branch from the result and remote HEADs (grep -v "^*" and grep -v "\->"). In the last step it prepends --not to each branch to tell git log to exclude this reference.

Note: Remote HEADs look like this remote/origin/HEAD -> remote/origin/master and mess with git log.

If you would type the command by hand it could look like this:

git log HEAD --not master --not origin/master
Sascha Wolf
  • 17,034
  • 4
  • 47
  • 72
0

You usually need to know from which branch you are coming from in order to list the commit specific to your current branch, as I explained in "Git log to get commits only for a specific branch"

Otherwise, you need to exclude the commits which are not part of only your branch (as suggested by dimirc):

git log mybranch --not $(git for-each-ref --format='%(refname)' refs/heads/ | grep -v "refs/heads/mybranch")

Or simpler, using git merge-base (if HEAD is not on your branch as in this question):

git log $(git merge-base HEAD branch)..branch
Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
-1

change your current git branch

git branch - > to list out the branches in the repos (* indicates you are in that branch, your commits will come under this branch) if you want to see the commit of any of the branch then

git checkout branchname -> change the branch which you want to see the commits then

git log -> will show you the commits under the branch

errakeshpd
  • 2,464
  • 2
  • 25
  • 35