8

Is there some shortcut to specify the interval of fetched, new commits from remote tracking branch? Instead of typing this long command that is also branch specific:

git log branchName..origin/branchName

I am looking for some git interval hack, that will represent interval of branchName..origin/branchName, something like (not working, equivalent to git log ..origin/HEAD)

git log ..origin
Phil Hord
  • 12,780
  • 1
  • 26
  • 30
kasi
  • 955
  • 1
  • 12
  • 21
  • You question is: when new commit execute, show log? I think this dependency your editor. Find extension like `git log` or `git history`. You can see `git history` in Visual Studio Code: https://github.com/DonJayamanne/gitHistoryVSCode and Atom: https://atom.io/packages/git-history – Ave Jul 18 '16 at 10:23
  • You can set up an alias to do fetch & log. See https://stackoverflow.com/questions/7534184/git-alias-multiple-commands-and-parameters. – Melebius Jul 18 '16 at 10:49
  • I was looking for some interval shortcut something like - this is completely invented by me - `git log ..origin`... – kasi Jul 18 '16 at 10:51

3 Answers3

12

This will do what you want, provided you have remote tracking configured for your branch:

git log ..@{u}

It will show all the commits on remotes/branch which are not already on your local branch. If you want to also see your local commits which have not been pushed, use three dots:

git log ...@{u}

Or if you want to see only your local commits which have not been pushed as of your last fetch, put the two dots after @{u}:

git log @{u}..

Explanation:

  • @{u} is shorthand for `HEAD@{upstream}
    • master@{upstream} means the remote tracking branch for my local 'master' branch. master@{upstream} is the same as origin/master if your master branch is tracking the remote branch named master on the remote named origin.
    • If you omit the branch name (e.g. master) then your current branch is used instead.
    • upstream can be abbreviated to u in this case. So @{u} is the same as master@{upstream} if your current branch is named master.
  • .. is used to specify a range of commits.
    • A..B is the same as ^A B which means show me all the commits in B but exclude those in A. It can also be written B --not A.
    • If you omit either reference, like A.. or ..B, then the omitted reference is presumed to be HEAD.
  • You can see what your upstream tracking is configured to with git rev-parse --symbolic-full-name @{u}
  • You can set your upstream tracking explicitly with git branch --set-upstream-to=origin/master

You can find all the details about revision specifications like this in the Git man pages:

git help revisions  

Or

man gitrevisions
Phil Hord
  • 12,780
  • 1
  • 26
  • 30
  • 1
    Thank you very much. This is exactly what I was looking for, just I do not understand, why I have negative reputation for this question... – kasi Feb 15 '17 at 06:55
0

This perhaps is not an answer but rather a long comment with a workaround you could apply to avoid re-typing the same thing over and over.

You could write yourself an alias, see example below

git config --global alias.branchlog \ `log branch..origin/branch`

alias.<name> - replace <name> with whatever you like as long as you can remember. You can call this function like this:

git branchlog
e.doroskevic
  • 2,129
  • 18
  • 25
  • Not exactly what I am looking for, see my edited question – kasi Jul 18 '16 at 13:37
  • I am sorry to hear that, I am afraid I do not know any other way how to simplify this operation. It will be interesting to see what others may post – e.doroskevic Jul 18 '16 at 13:51
  • Anyway, thanks for your time, I am also eager for information if some simpler way in git is possible. – kasi Jul 19 '16 at 07:26
-1

I haven't tested this.

  1. Create a bash file with the command: git log $1..origin/$1. Name it whatever you like (I am calling it foo.sh).

  2. Make sure it's executable: chmode +x foo.sh.

  3. run the git command: git config --global alias.branchhistory '!./path/to/foo.sh'

Now you are ready to try it as follows: git branchhistory master.

joker
  • 3,416
  • 2
  • 34
  • 37