From the course: Working with LinkedIn Learning Exercise Files on GitHub

Use Diff tools to compare two branches - GitHub Tutorial

From the course: Working with LinkedIn Learning Exercise Files on GitHub

Use Diff tools to compare two branches

- [Narrator] Git gives you great tools for comparing code from one branch to another, or from changes you've made to the original version of the current branch. I'll show you a few of these tricks here in IntelliJ IDEA. Let's say for example, that in this file I had created a new line and I'll say that I'm creating a new string that I'll call choice four and I'll give it a value of pluto. Now, if I want to compare this file to the original version of the current branch, I can go directly to my commit window. You can get there in a couple of different ways. You can click the commit tab on the left. If you click it again, it goes away. You can go up to the toolbar and click on the commit button and once again it appears and this time I'll make it disappear by clicking the hide icon or you can press the keyboard shortcut. And that's command key on Mac or control K on Windows. Once you've opened the commit window you can go to the file you're interested in, right click on it and choose show diff. And again, notice that there's a keyboard shortcut associated with it. When you choose that option you'll see a side-by-side viewer up here. You'll have the original code on the left and the new code on the right. If there is more than one difference, you can click on this down arrow and you'll be moving from one change to the next. Now let's say that you wanted to compare your changes to another branch. You can do that too. In order to compare it to another branch, that branch has to be local. So I'm going to go over to my branch list over here and I'm going to choose zero four zero two E, the ending state of this current video. I'll select it and I'll check it out and then I'll go back to the beginning state. So now I have both branches on my local hard drive. Now I'll go to the project window. I'll go to this file and right click on it. I'll choose the Git menu choice. And I'll select compare with branch and I'll choose zero four zero two E. And now I'm seeing my current branch over on the right and the ending state of this content on the left. In this particular video there aren't any other changes in the ending state, but this is how you can compare your current code to either the original state of the current branch or to any other branch in your repository. Again, the diff tools work on local copies of the branches. So check out the branches you need and then use diff to compare them.

Contents