In this movie, we're going to talk about how we can compare branches.
Now we saw in the last chapter, we talked about navigating the commit tree, so we could
use the git diff command in order to compare two different tree-ish objects.
And at the time, I told you that a branch was one of the tree-ish's that we can pass
in, but we didn't have any branches back then.
Now we have some branches so let's try comparing them.
Use git diff, and then we just pass in the names of the branches.
Let's remind ourselves that those branches are real quick.
There is a list of our branches, and I'm on the shorten title branch, let's say git diff
master..new_feature.
So I'm going to compare master with new feature by using that range operator in between, dot dot.
So master compared to new_feature, and it comes up and tells me what are the differences
between the tip of master and the tip of new_feature, the most recent commits there. That snapshot.
So I now can very easily see what changed between the two versions.
Try it again with master and shorten_title.
So there is what changed there.
That includes those changes that were made in the new feature branch, remember because
shorten title is a branch off of new_features, so it has all of those changes as well.
And of course, we can do the intermediary step git new_feature compared to shorten title.
The order of these doesn't really matter.
Let me just show you, let's do that one again, and now let's just flip them around, let's
do git diff shorten_title..new_feature.
It'll show us the exact same diff, it just flipped them around.
It changed which one was the a or minus and which one is the b or plus.
So that's all it did.
Typically the one that's further back in time, you would make the one that comes first, and
the one that comes later would be the one that made second.
But time can be kind of tricky when you start working with branches and different commits
are being made at different places.
So it really is just about which one you want to be the old state, and which one you want
to be the new state.
Another nice feature that we can use with diff is colorwords option.
So let's go with this one, the new_ feature..shorten_ title, and let's add in --color-words, with a space.
Now it comes up and shows with the same diff, but it shows it to us all on oneline.
So that might be a little clear for you as to what changed, instead of having the two
lines, one above each other.
It's really matter of personal preference for which one you like better.
Now of course, what we are passing in here is not just a branch, we are passing in a tree-ish.
We talked about tree-ishs.
A tree-ish can be a lot of things, it can even include the ancestors.
So for example, I can compare new_ feature with the previous commit to the HEAD of shorten_title.
So go to shorten_title, and it's not the last the commit, it's the commit right before that,
that I want to compare it to.
And we can see that what changed was I took out the words, welcome to.
There is one more important way that we can compare branches, and that's that we can find
out, whether one branch completely contains another branch or not.
That is whether or not everything in it has been merged into the current branch.
We do that by not using the diff tool but using git branch with the dash dash merged option after it.
That will show us all branches that are completely included in this branch.
So in this case we're on the shorten_title branch, all of the commits that are in new_feature
are also in shorten_title, all of the commits that are in master are also in shorten_title.
What that lets us know is that we can actually delete new feature if we wanted to and shorten_title
wouldn't be affected.
Shorten_title has all of those commits in it.
Let's try switching to different branch,
git checkout new_feature, surround it again, git branch merged.
Now it says, all right, new feature doesn't have all of the commits that are in shorten_title.
Shorten_title has some things that are not merged into here yet, we would need to do
a merge to get those changes into new feature first.
What it actually does is it goes back up the ancestor chain of the new_feature branch to
see does it have the tip of master in it.
If it has that final commit of master, then it has all of the ancestors as well.
It does not have the final commit of shorten_title so it doesn't list it here.
And just for good measure, let's do checkout master, and we will do the same thing there,
and you see that master doesn't contain those changes that are in new_feature and shorten_title.
So well, it's not strictly speaking comparing branches, the same way that diff does, I think
it's important way to get some information about the comparison of the content of what
is in each of the branches.
Those come in very handy soon, when we start trying to delete branches.