Git/C2/Stashing-and-Cleaning/English-timed

From Script | Spoken-Tutorial
Revision as of 16:36, 1 April 2016 by PoojaMoolya (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time
Narration
00:01 Welcome to the spoken tutorial on stashing and cleaning in Git.
00:07 In this tutorial, we will learn about stashing.
00:11 We will learn how to
  • Create a stash
  • Apply a stash and
  • Clean a stash
00:19 To record this tutorial, I am using
  • Ubuntu Linux 14.04
  • Git 2.3.2 and
  • gedit Text Editor
00:32 You can use any editor of your choice.
00:36 To follow this tutorial you must have knowledge of Git commands and branching in Git.
00:43 If not, for relevant tutorials, please visit our website.
00:48 Let us learn about stashing.
00:51 Stashing is used to save temporary changes of a branch.
00:57 It helps to pause the current work without committing it, when switching branches.
01:04 Stash of the temporary changes can be revoked at any time.
01:08 Recall that we already came across the term stash earlier in this tutorial series.
01:16 Now, let’s learn it in more detail.
01:20 Let us begin by opening the terminal.
01:25 We will open our Git repository mywebpage which we created earlier.
01:30 Type cd space mywebpage and press Enter.
01:35 I will continue to use html files for demonstration. You may use any file type of your choice.
01:44 From here onwards, please remember to press the Enter key after typing every command on the terminal.
01:52 First we will check the branch list by typing git space branch
01:58 I have already created a branch named chapter-three.
02:03 I have done a commit inside it, for demonstration purpose.
02:08 Please make sure that you also create a new branch and make a commit inside it.
02:15 We will go into the branch chapter-three by typing git space checkout space chapter-three
02:23 Let’s check the Git log.
02:26 This is the commit which I made in the chapter-three branch for demonstration.
02:31 Let’s check the folder content by typing ls
02:35 If you are working in Windows operating system, use dir command in place of ls command.
02:43 Note that here we have three html files.
02:47 Now, we’ll make some changes on the file mypage.html
02:53 Let us open the file mypage.html by typing gedit space mypage.html space ampersand.
03:03 I will copy and paste some lines into this file, from my Writer document, which I had saved earlier.
03:11 Then save and close the file.
03:14 To check the Git status, type git space status
03:19 We can understand that our changes are not staged yet.
03:24 When we work in a big project, we may need to switch branches frequently.
03:30 Now, let’s say, we want to go back to our master branch to work on something else.
03:37 Type git space checkout space master.
03:41 This error shows that we can't switch back to other branches without committing the changes.
03:48 I don't want to commit the changes right now, as my work is just half-done.
03:55 If we will forcefully exit this branch using the hyphen hyphen force flag, the changes will get discarded.
04:04 But what if I want to save the changes temporarily? This will be done using Stashing.
04:11 We can save the changes temporarily by typing git space stash space save space

within double quotes “Stashed mypage.html”

04:24 Here “Stashed mypage.html” is the stash name I have given. You can name it as per your preference.
04:34 On the terminal, the stash name and the branch name where the stash is created, is displayed.
04:42 We will check the Git status by typing git space status.You can see the message “nothing to commit”.
04:51 So we can switch branches now.
04:55 Now let's try to go into master branch by typing git space checkout space master.
05:03 Note that after stashing, we can switch to other branches.
05:07 Next, let us see another way of stashing.
05:11 For that, again I will go to chapter-three branch by typing git space checkout space chapter-three.
05:20 Now I will edit the file history.html. Type gedit space history.html space ampersand.
05:31 I will add some lines from my Writer document here.
05:35 Then save and close the file.
05:38 Let's check the Git status by typing git space status.
05:44 Say, for example, in stash I want to save these changes in another way. Type git space stash.
05:54 Note that we didn't give the stash name here.
05:58 If we don't give the stash name, the stash will be saved in the name of the latest commit.
06:04 Next, we will check whether the stash name and the latest commit are same.
06:10 Let's check the Git log first.
06:14 To check the stash list, type git space stash space list.
06:20 You can see that the latest commit and the latest stash name are same.
06:25 Note that the latest stash is listed first. Which means the stashes are listed in chronological order.
06:35 This is the stash id which will be generated automatically.
06:40 I will create one more stash for demonstration purpose.
06:45 For that, I will edit the file story.html. Type gedit space story.html space ampersand.
06:55 I will add some lines in the file story.html.
07:00 Then save and close the file.
07:03 Now I will save the changes in a stash.
07:07 Type git space stash space save space within double quotes “Stashed story.html”.
07:17 Let's check the stash list by typing git space stash space list.
07:24 We can see that now we have three stashes in the chapter-three branch.
07:30 In certain situations, we may not remember what changes we have saved in the stashes.
07:36 Let us see how to check it.
07:40 Say, for example, I want to see the details of stash@{0}.
07:45 So, type git space diff space stash at the rate symbol within curly brackets zero
07:54 We can see the changes of story.html. That is what we saved in stash@{0}.
08:01 Next we will continue to work on the stashed files.
08:06 For that, first we have to apply the stashes.
08:10 To check the stash list, type git space stash space list.
08:17 For example, now we will apply the stash@{1}.
08:21 To do so, type git space stash space apply space stash @ (at the rate symbol) within curly brackets one.
08:33 If you don't mention the stash id, the latest stash (i.e) stash@{0} will be applied.
08:40 You can see that our stash is applied successfully.
08:44 Let's check the stash list by typing git space stash space list.
08:51 We can see the stash@{1} still in the list and this may lead to confusion in future.
08:58 So after applying a stash, it is better to delete it manually.
09:03 To delete the stash@{1}, type git space stash space drop space stash@ (at the rate symbol) within curly brackets one.
09:16 To check the stash list, type git space stash space list.
09:22 We can see that our stash@{1} is removed. And stash@{2} became stash@{1}.
09:30 Now, we will learn to apply a stash in another way. Type git space stash space pop.
09:39 We can see that our stash@{0} is applied.
09:43 So, if we use stash pop command, the most recent stash (i.e) stash@{0} will be applied.
09:52 Again we will check the stash list by typing git space stash space list.
09:59 Now we can see that stash@{0} is removed. And stash@{1} became stash@{0}.
10:07 So the stash pop command will apply the stash@{0} and delete it automatically.
10:15 Next we will learn how to remove all the stashes at once.
10:20 To delete all the stashes from our repository, type git space stash space clear.
10:28 Again, we will check the stash list by typing git space stash space list.
10:36 We can see that our stash list is empty now.
10:40 With this, we come to the end of this tutorial.
10:44 Let us summarize.
10:46 In this tutorial, we have learnt about Stashing.
10:51 We also learnt how to
  • Create a stash
  • Apply a stash and
  • Clean a stash
10:58 As an assignment Create three stashes in your repository
11:03 Explore the command git stash show
11:07 Understand the difference between the commands git stash show and git stash show stash@{1}
11:14 Apply the latest stash (Use – git stash pop)
11:21 And delete all the stashes from the repository.

(Hint – git stash clear)

11:28 The video at the following link summarises the Spoken Tutorial project. Please download and watch it.
11:36 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:01 This is Priya from IIT Bombay. Thanks for joining.

Contributors and Content Editors

PoojaMoolya, Sandhya.np14