git - Showing which files have changed between two revisions

ID : 360

viewed : 125

Tags : gitbranchgit-branchgit-diffgit

Top 5 Answer for git - Showing which files have changed between two revisions

vote vote


To compare the current branch against main branch:

$ git diff --name-status main 

To compare any two branches:

$ git diff --name-status firstbranch..yourBranchName 

There is more options to git diff in the official documentation (and specifically --name-status option).

vote vote



$ 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 
vote vote


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.

vote vote


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

git diff master..otherbranch > myDiffFile.diff 
vote vote


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.

Top 3 video Explaining git - Showing which files have changed between two revisions