Git/C2/Inspection-and-Comparison-of-Git/English-timed
From Script | Spoken-Tutorial
Revision as of 19:51, 8 March 2017 by PoojaMoolya (Talk | contribs)
|
|
00:01 | Welcome to the spoken tutorial on Inspection and comparison of Git. |
00:06 | In this tutorial, we will learn about:
git diff git show git blame and git help commands. |
00:17 | For this tutorial, I am using-
Ubuntu Linux 14.04 Git 2.3.2 and gedit Text Editor. |
00:29 | You can use any editor of your choice. |
00:33 | To follow this tutorial, you must have knowledge of running Linux commands on Terminal. |
00:40 | If not, for relevant Linux tutorials, please visit our website. |
00:46 | Let us begin with git diff command. |
00:50 | This command will show the changes of the current status of the files. |
00:55 | Now, I will show you how it works. Press Ctrl+Alt+T to open the terminal. |
01:03 | We will go into our Git repository mywebpage which we created earlier. |
01:09 | Type: cd space mywebpage and press Enter. |
01:15 | I will continue to use html files for demonstration. |
01:20 | You may use any file type of your choice. |
01:24 | First, I will create a html file history.html and commit it for demonstration purpose. |
01:32 | Type: gedit space history.html space ampersand and press Enter. |
01:41 | I will copy and paste some code into this file, from my Writer document, which I had saved earlier. |
01:48 | Let us save and close the file. |
01:51 | Recall that we have to commit our work whenever we add or remove any file. |
01:58 | To add the file to the staging area, type: git space add space history.html and press Enter. |
02:08 | To commit our work, type: git space commit space hyphen m space within double quotes “Added history.html” and press Enter. |
02:21 | Let's see the Git log by typing git space log and press Enter. |
02:28 | Currently, we have two commits in our repository. |
02:33 | Open the files mypage.html and history.html by typing gedit space mypage.html space history.html space ampersand |
02:47 | Here, mypage.html is the file which we created in the previous tutorial. Now, press Enter. |
02:56 | Let us add and delete some lines in these files. |
03:01 | Then save and close the files. |
03:05 | In certain situations, we may not remember what changes we have made in our files. |
03:11 | Let us check the Git status by typing git space status and press Enter. |
03:19 | It simply shows the modified file names. But we cannot get any other details. |
03:26 | We want to know the actual changes that have been made to these files. Let us see how to check it. |
03:35 | Type: git space diff and press Enter. |
03:40 | This command will compare the current state of the files with the latest commit. |
03:46 | Here you will see the two versions of the file history.html. |
03:51 | a slash history.html is the version of last commit. And, it is represented by a minus sign. |
04:00 | b slash history.html is the version of current state. And, it is represented by a plus sign. |
04:09 | So, here the red color line with the minus sign is the old version. |
04:15 | And, the green color line with the plus sign is the new version. |
04:20 | Press down arrow key to see more. |
04:23 | These are the lines which we added in the new version. |
04:28 | Also, you can see the changes of the filemypage.html. Press down arrow key. |
04:35 | Press q key to exit. |
04:38 | Here, the output is displayed in colors. |
04:42 | If we can’t see the lines with colors, type: git space config space hyphen hyphen global space color dot ui space true and press Enter. |
04:57 | If you don't want to see the colors, please use false instead of true in this command. |
05:03 | Type: git space diff and press Enter. Now, the output is displayed without colors. |
05:13 | Next, I will show you how to see the changes in a particular file. |
05:18 | Type: git space diff space history.html and press Enter. |
05:25 | Here, we can see the changes made in the file history.html only. |
05:31 | Let us now add our files to the staging area. Type: git space add space history.html space mypage.html and press Enter. |
05:44 | Let’s check the Git diff again by typing git space diff and press Enter. |
05:52 | This time, we don’t get any output because our files have been added to the staging area. |
05:59 | In such a case, we can type: git space diff space hyphen hyphen staged and press Enter. |
06:08 | Now, we can see the same output just like the one we got in the git diff command. |
06:15 | We can also use hyphen hyphen cached instead of hyphen hyphen staged to get the same result. |
06:23 | How can we compare the current state with any previous commit? |
06:28 | First we will see the Git log by typing git space log space hyphen hyphen oneline and press Enter. |
06:38 | Now, say, I want to compare my current state with the Initial commit. |
06:43 | So, type: git space diff space, then copy and paste the commit hash of the Initial commit and press Enter. |
06:52 | Here, we can see the difference. |
06:55 | In this manner, we can compare our current state with any previous commit in our repository. |
07:02 | In this way, using git diff command we can see all the changes in the modified files. |
07:09 | It will help us to make sure what exactly we have changed before committing. |
07:15 | Let us freeze our work at this point. |
07:19 | To commit, type: git space commit space hyphen m space within double quotes “Added colors” and press Enter. |
07:30 | Next, let us learn how to see the difference between two commits. |
07:35 | Let’s check the Git log by typing git space log space hyphen hyphen oneline and press Enter. |
07:44 | Type: git space diff space then copy and paste the commit hash of “Initial commit” space.
Now, copy and paste the commit hash of “Added colors” and press Enter. |
07:58 | The difference between the two given commits can now be seen. |
08:03 | Next, we will compare the last revision with the second last revision. |
08:08 | Type: git space diff space HEAD space HEAD tilde and press Enter. |
08:16 | HEAD indicates the last revision which has the commit message “Added colors”. |
08:22 | HEAD tilde indicates the second last revision which has the commit message “Added history.html”. |
08:30 | The latest revision is always HEAD. The latest minus 1 revision is always HEAD tilde. |
08:39 | Likewise, latest minus 2 is HEAD tilde 2, latest minus 3 is HEAD tilde 3 and so on. |
08:50 | Switch back to the terminal. |
08:53 | Let us now learn about git show command which helps to see the entire details of a commit. |
09:00 | Type: git space show and press Enter. |
09:04 | This command will show the details of latest commit in the repository. |
09:10 | It shows what changes have been made to the files along with the commit details. |
09:16 | This feature is helpful when we work collaboratively. |
09:20 | Now, let’s see the Git log by typing git space log space hyphen hyphen oneline and press Enter. |
09:30 | To see the details of the Initial commit, type: git space show space . Then copy and paste the commit hash of the Initial commit and press Enter. |
09:42 | Here, you can see the details of the Initial commit. |
09:46 | In this manner, we can see the details of any commit of our repository. |
09:51 | Next, let us learn how to see the entire history of a file. |
09:56 | To see the entire history of mypage.html, type: git space blame space mypage.html and press Enter. |
10:07 | Here, we can see the entire history of the file mypage.html i.e. from creation point up to current stage. |
10:17 | Likewise, you can see the full details of any file in your repository. |
10:22 | Lastly, we will see how to get help from Git. |
10:27 | The syntax to get help, is as follows-
git help <verb> OR git <verb> hyphen hyphen help OR man git <verb> |
10:40 | For example: git help show. |
10:44 | Let me demonstrate this. Switch back to the terminal and type: git space help space show and press Enter. |
10:55 | Here, we can see the manual of show command. |
10:59 | With this, we come to the end of this tutorial. |
11:03 | Let us summarize.In this tutorial, we have learnt about:
git diff git show git blame and git help commands. |
11:15 | As an assignment, explore the following commands:
git reflog git diff HEAD tilde HEAD git show HEAD and man git diff. |
11:29 | The video at the following link summarizes the Spoken Tutorial project. Please download and watch it. |
11:37 | The Spoken Tutorial Project team conducts workshops and gives certificates to those who pass online tests. For more details, please write to us. |
11:48 | Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India. |
11:55 | More information on this mission is available at the following link. |
12:00 | This is Priya from IIT Bombay. Thanks for joining. |