Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 816
kasi Avatar asked Jul 18 '16 10:07

kasi


People also ask

How do I check fetched changes?

You can use the command git log to view the updated commits from the remote. One of the main use-cases of git fetch is to see the changes before merging the current branch. So that you are always sure, what changes are already made and it will easy to resolve conflicts beforehand.

How do I see my git upstream?

You can check tracking branches by running the “git branch” command with the “-vv” option. We can set the upstream branch using the “git push” command. $ git push -u origin branch Total 0 (delta 0), reused 0 (delta 0) * [new branch] branch -> branch Branch 'branch' set up to track remote branch 'branch' from 'origin'.

What happens after git fetch?

The git fetch command downloads commits, files, and refs from a remote repository into your local repo. Fetching is what you do when you want to see what everybody else has been working on.

What is git fetch upstream?

git fetch is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn't do any file transferring. It's more like just checking to see if there are any changes available). git pull on the other hand does that AND brings (copy) those changes from the remote repository.


1 Answers

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
like image 126
Phil Hord Avatar answered Oct 21 '22 06:10

Phil Hord