Viewing and Comparing changes - between Git Commits (Lab)

Bibhash Roy
A free video tutorial from Bibhash Roy
Developer, Architect, Spring, Devops Trainer & Entrepreneur
4.3 instructor rating • 2 courses • 17,459 students

Learn more from the full course

Git & GitHub Complete Masterclass : Beginner to Git Expert

Most comprehensive, STEP by STEP Git & GitHub tutorial with great & easy to understand examples and Quizzes.

12:31:12 of on-demand video • Updated September 2020

  • Build rock solid foundation in Git and related concepts
  • Learn Git installation on multiple platforms
  • Learn how to configure git repository in 3 ways
  • Learn how to modify, add and commit artifacts
  • Learn how to inspect Git repository using status and log checks
  • Learn Git branching basics
  • Learn to basics of public key cryptography
  • Learn GitHub and how use and manage the web based Git repository
  • Learn how to communicate with GitHub from local repository
  • Learn HTTPS and SSH connection with GitHub
  • Learn details of connection management
  • Learn basic file management in git bash environment
  • Learn how to customize/colorize Git bash prompt for productivity
  • Learn how to undo changes in Git repository through checkout, reset, revert and clean
  • Learn how to install and configure "Sublime Text" as the default text editor for Git
  • Learn how to install and configure "p4merge" as Git diff and merge tool
  • Learn how to perform Git comparisons between various sections of a Git repository
English Hey they're welcome. So in this lecture I will show you how to find the diff or the difference between an arbitrary commit and the head. I will just show you how to inspect the difference between two arbitrary commits and how to inspect the difference between head and head minus one which means the commit previous to the head. So let's get going. So consider a couple of changes in the repository. So I'd simply just commit them away so you can see there has been an addition in the staging area as well as there is a modification. OK so let's inspect what was the change we made since we made the earlier lecture. So let's do git diff. And then you can see that we have added the line hiding and forming the hr, administrative and purchase departments.OK let's clear the screen and let's do an express commit using get commit. There's -a -m. And let's start a message forming various departments hr, admin, etc quotes closed. Press enter and the commit is done and you have a clean working directory now. OK. So let's see what is the state of our commit history now using git log - one line press enter. So well we have five commits as you can see over here and now we'll actually inspect the difference between the head and the commit prior to the head. So the inspection should be between this commit id as you can see I've highlighted and this second one. So let's do a git diff first using git diff command. So since the difference is between this commit ID and the head we'll copy this commit ID paste it and the head. We don't need to really test this one because the head reference will do the job. So lets press enter. So diff tells us that these are the two lines that forms the difference between the head and the previous commit ID and that's perfectly OK. Since remember there were two changes as we saw our earlier.One that was pending to be committed and was in staging area. And the other was in the modified state. So these are the two lines that were committed in our last commit. So let's clear the screen so let's make some additional changes to the major milestone files. So vim major milestones press enter and you're in the editor press I key to insert and let's go down to the end and press enter once again. Now that we have formed that hr ,administrative and purchase department.So let's reach the milestone of doing some purchase by purchasing department and some action from the administrative department. So admin for short for administrative department purchases office stationeries and purchase department so dept,short for department purchases office equipments such as computers and printers. That's press the escape key :wq to quit and save. OK so let's clear the screen .So I just retrieved the earlier command which I used regarding git diff I'll simply append the word tool for issuing git diff command. Press enter and here we are. So the diff launches p4merge and we had the left side and as well as the right side part of the diff tool. And here we can see here this is from the left side and this on the right side. Any can correlate directly over here. The left side and the right side. So this one is actually the commit part corresponding to the head. And this is the commit part corresponding to the head minus one. And here is a major milestone file which represents the head. And that's a temporary file you can see is in app data local temp and this is a major milestone file component corresponding to the head minus one. And this too is it temporary files and the diff tool very nicely and clearly depicts the difference between head and head minus one and since head minus one or a commit prior to the head did not include these two lines they are clearly showed as the difference between the two. So let's exit from the tool using file and then exit and you're back in the terminal. Now let's check the log once again using git log --one line and let's retrieve our earlier command which was git diff tool 9d22ac3. So this was the commit just prior to the head. Now in an alternative syntax we can write this as head caret and that will represent this commit ID which you can see over here. And now let's test this out. Press enter and here we go. So head caret is a commit ID which is prior to the final commit or head. So this is represented by the left panel and head as usual is represented by the right panel and the diff as you can see as earlier are these two lines which forms the difference between head and head minus one that is commit prior to the head. So let's exit from the tool. File Exit. Now I'll show you another alternative syntax. Here I'll retrieve the earlier command and head caret. It can also be represented as head tilde one. So let's press enter and here you are head ~1 Again head minus one again the commit prior to the head or head^ and head as usual is here represented by the right panel and these two lines remains. Obviously the difference between head and head minus one. So let's exit from the tool and file exit. OK let's clear the screen. OK let's do an ls to check the contents of the directory. So apart from the major milestones we have several other documents. So let's modify some of them .We'll modify at least two files. So let me modify the marketing doc ,press and enter and we are right in the editor. So let's add our first line. So our first line will be we need to hire a marketing manager to run the ad campaigns so ad mean advertisement here. Press Escape key : wq to quit and save and let's do modification of another document and let it be the sales document. So sales stuff,press I key to insert and we add one line here.So you don't want to hire another sales manager. So we'll add another line over here. So as we are just a startup company we don't want to increase our expenses. So we'll try to manage our sales force under the guidance of marketing manager. So there is a typo here. I'll just edit this. So it our .Press escape key : wq to quit and save. So let's do an express commit using get commit for all the changes we make git commit -am.So our commit message has added entries to sales and marketing docs quotes closed. Press enter and the commit is done .We'll further go ahead and modify the major milestones document .press I key to insert and we go down below. So a company has started functioning development process has begun and we have achieved a prototype of our product that we want to market. So the next milestone that we achieved is ,we have developed an MVP. So MVP means minimal viable product for demo. So demo means demonstration part, press escape key wq to quit and save and let's commit this one too. So we'll modify the earlier commit message we'll do an express commit this time as well. So our commit message is building a MVP. Press enter and the commit is done. So let's check what is the status of our commit history using git log one line press enter .So we have further more you have two commits over here as you can see .Now I'll show you right now how to find the diff or difference between two arbitrary commits. So our first commit that we choose here is this one which is head minus one and let's choose this one right. So command on will be git diff. So we'll copy this commit paste it right over here and the next commit we need is this one. So let's press this commit tool over here and let's press enter and here you go. So you can see there are several changes of here this time it involves more than one file. So you can see over here is the marketing dock and you can see the color over here. This means we have more to scroll. So press space bar I have come to the end and I can see more docs over here which is the sales doc on you have to reach the end here as well. So let's press Q to quit and let's clear the screen and I'll make a few more changes to the marketing doc and the sales doc. So press enter and here we are in the marketing document .Enter, go to the next line and we add our next information. So the next entry in is document is This we need to identify the major market segments. Press escape key : wq to to to quit and save .Next we modified the sales doc press tab press I key to insert we go at end and add. another information here. So our next entry is we need to identify the sales territories .Press escape key: wq to quit and save.Let's clear the screen. Now I have a retrieved our earlier command which was git diff and i'll simply append the tool word to git diff and we have git tool command and press enter. And here we go. So you are comparing the difference between two arbitrary comics. So this represents the left pane and this represents the right pane. And here is the actual difference. Now the p4merge will cycle through all the documents. Since this diff involves more than one file so major milestone sales docs and marketing doc. So this is a temporary file representing this commit and this is another temporary file representing this commit both representing the document major milestone. So let's exit from the file exit and p4merge launches again cycling to the next document which is the marketing doc .As usual this commit ID represents the left pane and this commit ID represents right pain. And this is the difference as you can easily guess .Let's exit from here, file exit and p4merge launches once again citing to the last document which is a sales doc. As usual this one represents a left pane and this commit ID represents the right pane. And as you can easily understand this is the difference between these two commit IDs from the perspective of sales document .Let's exit from here, file exit and we're back in the terminal. Since p4merge has cycled through all the necessary documents. OK so with this we conclude this lecture.