Showing which files have changed between two revisions

I want to merge two branches that have been separated for a while and wanted to know which files have been modified.

Came across this link: http://linux.yyz.us/git-howto.html which was quite useful.

  • Checking out a remote git branch that does not exist locally?
  • Reusing a merged development branch / Remerging into an unchanged stable branch with git
  • Mercurial: Named Branches vs Multiple Repositories
  • git branch merging
  • Svn to git: How to deal with our not-standard, probably wrongly branched svn
  • Missing ranges error message when reintegrating a branch into trunk in Subversion 1.5
  • The tools to compare branches I’ve come across are:

    • git diff master..branch
    • git log master..branch
    • git shortlog master..branch

    Was wondering if there’s something like “git status master..branch” to only see those files that are different between the two branches.

    Without creating a new tool, I think this is the closest you can get to do that now (which of course will show repeats if a file was modified more than once):

    • git diff master..branch | grep "^diff"

    Was wondering if there’s something I missed…

  • Cloning git repository from svn repository, results in file-less, remote-branch-less git repo
  • Gcloud can't work with git
  • How do I revert back to a former Git commit and then save it in a separate branch?
  • Git - 2 projects sharing features
  • Create a git patch between repository and non-repository
  • Git: Diff does not handles character encoding other than UTF-8?
  • 13 Solutions collect form web for “Showing which files have changed between two revisions”

    Try

    $ git diff --name-status master..branchName
    

    That should do what you need, if I understand you correctly.

    Try

    $ git diff --stat --color master..branchName
    

    This will give you more info about each change, while still using the same number of lines.

    You can also flip the branches to get an even clearer picture of the difference if you were to merge the other way:

    $ git diff --stat --color branchName..master
    

    Also keep in mind that git has cheap and easy branching. If I think a merge could be problematic I create a branch for the merge. So if master has the changes I want to merge in and ba is my branch that needs the code from master I might do the following:

    git checkout ba
    git checkout -b ba-merge
    git merge master
    .... review new code and fix conflicts....
    git commit
    git checkout ba
    git merge ba-merge
    git branch -d ba-merge
    git merge master
    

    End result is that I got to try out the merge on a throw-away branch before screwing with my branch. If I get my self tangled up I can just delete the ba-merge branch and start over.

    If anyone is trying to generate a diff file from two branches :

    git diff master..otherbranch > myDiffFile.diff
    

    There is also a GUI based method.

    You can use gitk.

    1. Run:

      $ gitk --all
      
    2. Right click on a commit of a branch and select Mark this commit in the pop-up menu.

    3. Right click on a commit of another branch and select Diff this -> marked commit or Diff marked commit -> this.

    Then there will be a changed files list in the right bottom panel and diff details in the left bottom panel.

    Note that git makes it easy to just try out the merge and back away from any problems if you don’t like the result. It might be easier than looking for potential problems in advance.

    One more option, using meld in this case:

    git difftool -d master otherbranch
    

    This allows not only to see the differences between files, but also provides a easy way to point and click into a specific file.

    When working collaboratively, or on multiple features at once, it’s common that the upstream or even your master contains work that is not included in your branch, and will incorrectly appear in basic diffs.

    If your Upstream may have moved, you should do this:

    git fetch
    git diff origin/master...
    

    Just using git diff master can include, or fail to include, relevant changes.

    If you are using IntelliJ IDEA, you can also compare any branch with your current working branch. See http://www.jetbrains.com/idea/webhelp/merging-deleting-and-comparing-branches.html#d288093e3827 for more info. This is available in the free edition as well.

    And if you are looking for changes only among certain file(s), then:

    git diff branch1 branch2 -- myfile1.js myfile2.js
    

    branch1 is optional and your current branch (the branch you are on) will be considered by default if branch1 is not provided.
    e.g:

    git diff master -- controller/index.js
    

    Just additional info to JasonSmith’s answer:

    I checked out my branch with this command:

    $ git clone -b branchName http://repository_url

    However, suggested git diff command was failing:

    $ git diff --name-status master..branchName
    fatal: ambiguous argument 'master..branchName': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'
    

    I investigated branches following this thread:

    $ git branch
    * branchName
    $ git branch -a
    * branchName
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
      remotes/origin/branchName
    

    I didn’t have branch master locally, so I performed the comparison against remotes/origin/master instead:

    $ git diff --name-status remotes/origin/master..push
    . . .
    . . .
    . . .
    

    More info on remotes/origin/master in this thread.

    There are two branches lets say

    • A (Branch on which you are working)
    • B (Another branch with which you want to compare)

    Being in branch A you can type

    git diff --color B
    

    then this will give you a output of

    enter image description here

    The important point about this is

    1. Text in green is inside present in Branch A

    2. Text in red is present in Branch B

    There are plenty of answers here, but I wanted to add something that I commonly use. IF you are in one of the branches that you would like to compare I typically do one of the following. For the sake of this answer we will say that we are in our secondary branch. Depending on what view you need at the time will depend on which you choose, but most of the time I’m using the second option of the two. The first option may be handy if you are trying to revert back to an original copy — either way, both get the job done!

    This will compare master to the branch that we are in (which is secondary) and the original code will be the added lines and the new code will be considered the removed lines

    git diff ..master
    

    OR

    This will also compare master to the branch that we are in (which is secondary) and the original code will be the old lines and the new code will be the new lines

    git diff master..
    
    Git Baby is a git and github fan, let's start git clone.