Git/C2/Inspection-and-Comparison-of-Git/English

From Script | Spoken-Tutorial
Revision as of 15:47, 24 June 2015 by Nancyvarkey (Talk | contribs)

Jump to: navigation, search

Title of script: Inspection and comparison of Git

Author: Priya K

Keywords: Video tutorial, git diff, git show, git help, git blame, HEAD, HEAD~, color.ui


Visual cue
Narration
Slide 1:


Welcome to the spoken tutorial on Inspection and comparison of Git.
Slide 2: In this tutorial, we will learn about
  • git diff
  • git show
  • git blame and
  • git help commands
Slide 3:


For this tutorial, I am using-
  • Ubuntu Linux 14.04
  • Git 2.3.2 and
  • gedit Text Editor

You can use any editor of your choice.

Slide 4:


To follow this tutorial-
  • You must have knowledge of running Linux commands on Terminal.
  • If not, for relevant Linux tutorials, please visit our website.
Let us begin with git diff command.


This command will show the changes of the current status of the files.

Press Ctrl+Alt+T to open the terminal Now I will show how it works.


Press Ctrl+Alt+T to open the terminal.

Type cd mywebpage and press Enter We will go into our Git repository mywebpage which we created earlier.


Type cd space mywebpage and press Enter.

I will continue to use html files for demonstration.


You may use any file type of your choice.

Type gedit history.html & and press Enter First I will create a html file history.html and commit it for demonstration purpose.


Type, gedit space history.html space ampersand

and press Enter.

Copy and paste the code into the file I will copy and paste some code into this file, from my Writer document, which I had saved earlier.
Save and close the file Let us save and close the file.
Recall that we have to commit our work whenever we add or remove any file.
Type git add history.html and press Enter To add the file to the staging area, type

git space add space history.html


and press Enter.

Type git commit -m “Added history.html” and press Enter To commit our work, type

git space commit space hyphen m space within double quotes “Added history.html”


and press Enter.

Type git log and press Enter Lets see the Git log by typing git space log and press Enter.
Highlight the commits Currently, we have two commits in our repository.


<<PAUSE>>

Type gedit mypage.html history.html &


Highlight mypage.html


Press Enter

Open the files mypage.html and history.html, by typing


gedit space mypage.html space history.html space ampersand


Here mypage.html is the file which we created in the previous tutorial.


Now press Enter.

Add and delete lines Let us add and delete some lines in these files.
Save and close the files Then save and close the files.
Type git status and press Enter


In certain situations, we may not remember what changes we have made in our files.


Let us check the Git status by typing git space status and press Enter.

Highlight “modified: mypage.html history.html” It simply shows the modified file names.


But we cannot get any other details.

We want to know the actual changes that have been made to these files.


Let us see how to check it.

Type git diff and press Enter Type git space diff and press Enter.
This command will compare the current state of the files with the latest commit.
Highlight a/history.html b/history .html Here you will see the two versions of the file history.html.
Highlight ---a/history .html a slash history.html is the version of last commit.

And it is represented by a minus sign.

Highlight +++b/history .html b slash history.html is the version of current state.

And it is represented by a plus sign.

Highlight -<body> So, here the red color line with the minus sign is the old version.
Highlight +<body text="blue" bgcolor="green"> And the green color line with the plus sign is the new version.
Press down arrow key


Highlight the new lines

Press down arrow key to see more.


These are the lines which we added in the new version.

Show the changes of history.html Also you can see the changes of the file history.html.


Press down arrow key.


Press q key to exit.

Highlight the color lines Here the output is displayed in colors.
Highlight red and green color lines


Type git config --global color.ui true and press Enter

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.

Type git config --global color.ui false and press Enter If you don't want to see the colors, please use false instead of true in this command.
Highlight the lines Now the output is displayed without colors.


<<PAUSE>>

Type git diff history.html and press Enter Next I will show you how to see the changes in a particular file.


Type git space diff space history.html and press Enter.


Here we can see the changes made in the file history.html only.


<<PAUSE>>

Type git add history.html mypage.html press Enter Let us now add our files to the staging area.


Type git space add space history.html space mypage.html and press Enter.

Type git diff and press Enter Let’s check the Git diff again by typing git space diff and press Enter.
This time we don’t get any output because our files have been added to the staging area.
Type git diff --staged and press Enter In such a case, we can type

git space diff space hyphen hyphen staged

and press Enter.


Now we can see the same output just like the one we got in the git diff command.

Type git diff --cached and press Enter We can also use
  • hyphen hyphen cached
  • instead of hyphen hyphen staged

to get the same result.

How can we compare the current state with any previous commit?
Type git log --oneline and press Enter First we will see the Git log by typing

git space log space hyphen hyphen oneline


and press Enter.

Type git diff hash and press Enter Now say, I want to compare my current state with the Initial commit.


So type git space diff space, then copy and paste the commit hash of the Initial commit and press Enter.

Show the difference Here we can see the difference.
In this manner, we can compare our current state with any previous commit in our repository.
In this way, using git diff command we can see all the changes in the modified files.


It will help us to make sure what exactly we have changed before committing.


<<PAUSE>>

Let us freeze our work at this point.
Type git commit -m “Added colors” and press Enter To commit, type

git space commit space hyphen m space

within double quotes “Added colors”

and press Enter.


<<PAUSE>>

Next, let us learn how to see the difference between two commits.
Type git log --oneline and press Enter Let’s check the Git log by typing

git space log space hyphen hyphen oneline


and press Enter.

Type git diff hash hash and press Enter 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.

Show the difference The difference between the two given commits can now be seen.


<<PAUSE>>

Next, we will compare the last revision with the second last revision.
Type git diff HEAD HEAD~ and press Enter Type git space diff space HEAD space HEAD tilde and press Enter.
Highlight Added colors


Highlight Added history.html

HEAD indicates the last revision which has the commit message “Added colors”.


HEAD tilde indicates the second last revision which has the commit message “Added history.html”.

Slide 5:


The latest revision is always HEAD.

The latest minus 1 revision is always HEAD tilde.


Likewise,

Latest minus 2 is HEAD tilde 2,

Latest minus 3 is HEAD tilde 3 and so on.


<<PAUSE>>

Switch back to the terminal Switch back to the terminal.


Let us now learn about git show command which helps to see the entire details of a commit.

Type git show and press Enter Type git space show and press Enter.
Highlight commit details This command will show the details of latest commit in the repository.


It shows what changes have been made to the files along with the commit details.

This feature is helpful when we work collaboratively.
Type git log --oneline and press Enter Now, let’s see the Git log by typing

git space log space hyphen hyphen oneline


and press Enter.

Type git show hash and press Enter


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.

Here you can see the details of the Initial commit.
In this manner, we can see the details of any commit of our repository.


<<PAUSE>>

Next let us learn how to see the entire history of a file.
Type git blame mypage.html and press Enter To see the entire history of mypage.html,

type git space blame space mypage.html


and press Enter.

Show the history Here we can see the entire history of the file mypage.html

i.e. from creation point upto current stage.

Likewise, you can see the full details of any file in your repository.


<<PAUSE>>

Lastly, we will see how to get help from Git.
Slide 6:


The syntax to get help, is as follows


git help <verb> OR

git <verb> hyphen hyphen help OR

man git <verb>


For example: git help show

Switch back to the terminal

Type git help show and press Enter

Let me demonstrate this.


Switch back to the terminal and type

git space help space show


and press Enter.

Here we can see the manual of show command.


<<PAUSE>>

With this, we come to the end of this tutorial.
Slide 7:


Let us summarize.


In this tutorial, we have learnt about

  • git diff
  • git show
  • git blame and
  • git help commands
Slide 8:


As an assignment

Explore the following commands

  • git reflog
  • git diff HEAD tilde HEAD
  • git show HEAD and
  • man git diff
Slide 9:

Acknowledgement


The video at the following link summarises the Spoken Tutorial project.


Please download and watch it.

Slide 10:

Acknowledgement

The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.


For more details, please write to us.

Slide 11:

Acknowledgement

Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.


More information on this Mission is available at the following link.

This is Priya from IIT Bombay. Thanks for joining.

Contributors and Content Editors

Nancyvarkey, Priyacst