Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to git diff all changes since branching from master?

Tags:

git

git-diff

I've made several commits on my branch and now I was to see the changes from when I branched from master. However not the current master as that now has other branches merged in since I originally branched off it.

Similar to Show all commits in a git branch since original branching point from master but that is about the log.

I did try

git diff  --boundary master..

but I still see a lot more changes than just mine.

EDIT: I'm really hoping for a way that doesn't require any knowledge of SHA's or how many commits were made. If I don't need them I can automate and teach and automate and alias it more easily and trouble-free.

git diff my_branch_name...master

seems close but is not correct.

like image 712
Michael Durrant Avatar asked Dec 15 '15 00:12

Michael Durrant


People also ask

How do I see changes in git diff?

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.

How to see changes between different branches in Git?

For seeing the changes between different branches we will use the command git diff name_of _the_branch1 name_of_the_branch2. Now if we want to see all the changes on branch_2 for that we will use the command git diff branch1_name branch2_name.

How do I compare changes between two files in Git?

Comparing changes with git diff. Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

What is diffing in Git?

This tutorial will discuss, with examples, the basics of diffing with Git and how to use the git diff command. By the end of reading this tutorial, you’ll be an expert at using the git diff command. The git diff command displays the differences between files in two commits or between a commit and your current repository.

How do I use git diff to compare staged changes?

By default git diff will execute the comparison against HEAD. Omitting HEAD in the example above git diff ./path/to/file has the same effect. When git diff is invoked with the --cached option the diff will compare the staged changes with the local repository. The --cached option is synonymous with --staged.


1 Answers

As Jonathan Brink already noted, it sounds like you want to compare the version stored under the merge-base commit to the version at the tip of your own branch.

Using git merge-base --fork-point is usually overkill (and is not available on older versions of git, before git 1.9). It handles cases where the other branch has itself been rebased, so if that hasn't happened, you can stick with the simpler three-dot syntax from gitrevisions:

git diff master...my_branch_name

which (as you noted in a comment) can also be written using either HEAD or simply the empty string at the end:

git diff master...

When you use three dots, git diff finds the1 merge-base between the left and right side commit SHA-1s (as obtained from the names, or defaulting to HEAD) and substitutes that in for the left-side SHA-1. The right-side SHA-1 (as resolved from the name) remains intact.

Note that this is different from the two-dot syntax, and that git diff takes over both syntaxes (syntaces? no, syntaxes) so that neither one has its more-usual gitrevisions meaning.


1If there's more than one merge base, it just picks one of them. An actual git merge will (if you use the default "recursive" strategy) merge two "best" merge-bases to get a "virtual merge base", then use that to merge into your current HEAD commit. This case is pretty rare though.

like image 197
torek Avatar answered Sep 21 '22 08:09

torek