You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.
The git-difftool is a frontend to git-diff that accepts the same options and arguments. It allows you to compare and edit files between revisions. The following command will compare the develop branch against the master branch. That's all about comparing two branches in Git.
The following works for me:
git diff master:foo foo
In the past, it may have been:
git diff foo master:foo
You're trying to compare your working tree with a particular branch name, so you want this:
git diff master -- foo
Which is from this form of git-diff (see the git-diff manpage)
git diff [--options] <commit> [--] [<path>...]
This form is to view the changes you have in your working tree
relative to the named <commit>. You can use HEAD to compare it with
the latest commit, or a branch name to compare with the tip of a
different branch.
FYI, there is also a --cached
(aka --staged
) option for viewing the diff of what you've staged, rather than everything in your working tree:
git diff [--options] --cached [<commit>] [--] [<path>...]
This form is to view the changes you staged for the next commit
relative to the named <commit>.
...
--staged is a synonym of --cached.
git difftool tag/branch filename
Also: git diff master..feature foo
Since git diff foo master:foo
doesn't work on directories for me.
git diff mybranch master -- file
should also work
What also works:
git diff master ./relative-path-to-foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With