Git diff with remote tag

17,470

Solution 1

Most git commands only work locally, esp. things like git diff and git merge.

Your local repository can have multiple remotes, but in order to work on these, you must first sync the local repository with your remotes:

 git fetch --all

While this will download all the changesets, it will not apply them to your current branch, unless the current branch is tracking one of the remotes.

Once you have downloaded the remote changesets and tags, you can simply run something like:

git diff tagged_idea

... and see the diff between your current HEAD and a tag tagged_idea, wherever the latter resides.

Solution 2

I use git ls-remote --tags proposal |grep tagged_idea to get the revision hash, then do git diff with the hash.

Share:
17,470

Related videos on Youtube

aspyct
Author by

aspyct

Updated on September 20, 2022

Comments

  • aspyct
    aspyct over 1 year

    I'm about to merge a big change from a remote branch (non-origin), and more specifically from a given tag.

    There are two remotes then:

    1. origin
    2. proposal

    On the proposal remote, a branch name idea exists, with a tag tagged_idea.

    The idea is that I want to review the incoming changes between tagged_idea and my current HEAD. How can I achieve this?

    I tried something like git diff .../proposal/tags/tagged_idea but it didn't work well. Any idea?

    In other terms, what I would like to see is the result of the merge, before even doing it in my branch. Just like if I did the pull git pull proposal tags/tagged_idea but without actually making the changes.

  • torek
    torek over 10 years
    If you use git fetch instead of git pull, you'll still get all the new commits, but git will not attempt to merge (or rebase, depending on pull.rebase and other git config settings) any of those changes even if you're on a "tracking" branch. (There's a minor caveat if you normally track a force-pushed remote branch and auto-rebase with the "smart" rebase that git pull --rebase can do, but that's a very unusual work-flow.)
  • DylanYoung
    DylanYoung over 4 years
    This was the only solution that worked for me (the tags on the remote weren't fetched because the names matched the tags locally). Of course, the whole purpose of the diff was to see if there were any differences and where they came from: catch 22 ;)
  • ingyhere
    ingyhere over 2 years
    This does not work when you have local and remote tags with the same name. It only compares against the local tag.
  • ingyhere
    ingyhere over 2 years
    The hash definitively identifies the tag. Use git show-ref --tags -d to view local and remote tags. The local name should be followed by ^{} if there is a collision with an identically named tag.