0

There is a basic question about revision compare in git. I can compare current version with original version with

git diff HEAD^ HEAD

However, I need compare current version (origin/master) with current version of same branch on git server. It was pushed after get my original version. I tried to compare via commit id (got from web gitlab interface). However, there was the following error:

$ git difftool 866f426ce3c4d7594500ce322b68fd1d96ced06b
fatal: bad object 866f426ce3c4d7594500ce322b68fd1d96ced06b

There is an advice to use

git diff masterbranch remotebranch

For my case it looks like:

git diff master origin/master

In this case the diff is a comparison current version with original version I got as start for my changes. However, this branch was changed later. I would like to compare my version with actual state of branch origin/master not original one I used.

Loom
  • 9,768
  • 22
  • 60
  • 112
  • 2
    possible duplicate of [compare local git branch with remote branch?](http://stackoverflow.com/questions/1800783/compare-local-git-branch-with-remote-branch) – maggick Jun 17 '15 at 12:05
  • Thank you. However, both revisions are in same branch (`origin/mastet`) – Loom Jun 17 '15 at 12:11
  • `git diff master origin` will works – maggick Jun 17 '15 at 12:27
  • Thank you. However I have got `fatal: ambiguous argument 'origin': unknown revision or path not in the working tree.` – Loom Jun 17 '15 at 12:29

1 Answers1

1

2 ways to do that:

  1. directly diff with the remote server (need to be connected):

    git diff masterbranch remotebranch

    for instance

    git diff master origin

  2. Grab the code and diff localy :

    • do a fetch (the syntax is the same as git pull, but it doesn't automatically merge)
    • do a diff between your dest branch and the other branch
    • then do a merge if you want
maggick
  • 1,362
  • 13
  • 23
  • 1
    You may want to quote that second part since you copied it from [git diff between remote and local repo](https://stackoverflow.com/a/11935678). – Martijn Pieters Jun 17 '15 at 12:39
  • Thank you! (+1) Actually, the first way doesn't, because it's compare previous revision of the branch I used as start. The second approach works, but if it is possible, I would prefer way without uncontrolled code change like `git fetch` does. – Loom Jun 17 '15 at 14:01