burtonLowel
burtonLowel

Reputation: 794

Best way to check diff file by file between 2 branches/commits?

I just finished a fairly large branch that I've been working on for over 2 months. I just rebased master into it and had to resolve a handful of conflicts. Now that I have rebased my feature branch, how can I go through file by file to see the highlighted differences of that compare on the featured branch compared to the master branch to make sure the rebase was done correctly?

Upvotes: 2

Views: 1057

Answers (3)

Just Shadow
Just Shadow

Reputation: 11921

Most answers here suggest using git diff, but the con of that approach is that it shows the diff right in the console, which is not always convenient.
Here are some alternatives which will open GUI instead.

Using Gitk
Usually, while git (especially on Windows, with git-scm) you get a GUI tool called GitK which can be used to show the changes. So, just type:

gitk --all

And GUI will be opened where you can see the commits and the changes done by each commit.

enter image description here

Using DiffTool

Use git difftool instead, and show the diff in the preferred diff tool.
Just type difftool instead of diff in the console like this:

To see the changes between 2 branches:

# For all the files
git difftool branch1..branch2

# For a single file
git difftool branch1..branch2 "filepath"

To see the changes on the last commit

# For all the files
git difftool HEAD~1

# For a single file
git difftool HEAD~1 "filepath"

To see the changes since the commit with ID (all/single file):

# For all the files
git difftool commitId

# For a single file
git difftool commitId "filepath"

To see the changes between 2 commits:

# For all the files
git difftool commitId1..commitId2

# For a single file
git difftool commitId1..commitId2 "filepath"

Notes

  • The difftool will open your default diff tool which is usually set to VimDiff.
    But if you'd like to change it to something else, simply change id with this.
    In my case, I've used Visual Studio as a diff tool, and this is how it works: enter image description here
  • If you'd still like to see the changes right in the console, just use the commands above with git diff instead of git difftool by leaving the parameters the same.

Upvotes: 1

udit rawat
udit rawat

Reputation: 221

git diff branch1..branch2

Using this command, Git will compare the tip of both branches (also called the HEAD) and display a “diff” recap that you can use to see modifications. In short, it will show you all the commits that “branch2” has that are not in “branch1”.

git diff branch1...branch2

Using “git diff” with three dots compares the top of the right branch (the HEAD) with the common ancestor of the two branches.

Upvotes: 1

eftshift0
eftshift0

Reputation: 30317

Like this:

git diff master

You could provide a single file at a time:

git diff master -- some-file-path

Upvotes: 3

Related Questions