Is there a git command to show new upstream commits after fetch?
Asked Answered
V

3

9

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
Vesiculate answered 18/7, 2016 at 10:16 Comment(3)
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: github.com/DonJayamanne/gitHistoryVSCode and Atom: atom.io/packages/git-historyGravitative
You can set up an alias to do fetch & log. See #7534684.Benedetta
I was looking for some interval shortcut something like - this is completely invented by me - git log ..origin...Vesiculate
I
13

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
Interlocutor answered 30/11, 2016 at 17:47 Comment(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...Vesiculate
C
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
Conway answered 18/7, 2016 at 10:29 Comment(3)
Not exactly what I am looking for, see my edited questionVesiculate
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 postConway
Anyway, thanks for your time, I am also eager for information if some simpler way in git is possible.Vesiculate
E
-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.

Eskew answered 19/7, 2016 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.