Difference between revisions of "Git/C2/Stashing-and-Cleaning/English"
(Created page with "'''Title of script: Stashing and Cleaning''' '''Author:''' Priya K '''Keywords:''' '''Video tutorial, stashing, save stash, delete stash, save temporary changes, stash pop,...") |
Nancyvarkey (Talk | contribs) |
||
Line 25: | Line 25: | ||
We will learn how to | We will learn how to | ||
− | |||
* Create a''' stash''' | * Create a''' stash''' | ||
* Apply a''' stash''' and | * Apply a''' stash''' and | ||
* Clean''' '''a '''stash''' | * Clean''' '''a '''stash''' | ||
− | |||
− | |||
|- | |- | ||
Line 57: | Line 54: | ||
* You must have knowledge of '''Git''' commands and''' branching''' in''' Git'''. | * You must have knowledge of '''Git''' commands and''' branching''' in''' Git'''. | ||
* If not, for relevant tutorials, please visit our website. | * If not, for relevant tutorials, please visit our website. | ||
− | |||
− | |||
|- | |- | ||
Line 72: | Line 67: | ||
* It helps to pause the current work without committing it, when switching''' branches'''. | * It helps to pause the current work without committing it, when switching''' branches'''. | ||
* '''Stash''' of the temporary changes can be revoked at any time. | * '''Stash''' of the temporary changes can be revoked at any time. | ||
− | |||
− | |||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.097cm;"| | | style="border:1pt solid #000000;padding:0.097cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Recall that we | + | | style="border:1pt solid #000000;padding:0.097cm;"| Recall that we already came across the term''' stash''' earlier in this tutorial series. |
Line 114: | Line 107: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Highlight''' chapter-three''' | | style="border:1pt solid #000000;padding:0.097cm;"| Highlight''' chapter-three''' | ||
| style="border:1pt solid #000000;padding:0.097cm;"| I have already created a''' branch''' named''' chapter-three.''' | | style="border:1pt solid #000000;padding:0.097cm;"| I have already created a''' branch''' named''' chapter-three.''' | ||
− | |||
And I have done a '''commit''' inside it, for demonstration purpose. | And I have done a '''commit''' inside it, for demonstration purpose. | ||
− | |||
Please make sure that you also create a new '''branch''' and make a '''commit''' inside it. | Please make sure that you also create a new '''branch''' and make a '''commit''' inside it. | ||
Line 135: | Line 126: | ||
− | This is the commit which I made in the '''chapter-three branch '''for demonstration'''.''' | + | This is the '''commit''' which I made in the '''chapter-three branch '''for demonstration'''.''' |
|- | |- | ||
Line 167: | Line 158: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Copy and paste some lines | | style="border:1pt solid #000000;padding:0.097cm;"| Copy and paste some lines | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| I will copy and paste some lines into this file, from | + | | style="border:1pt solid #000000;padding:0.097cm;"| I will copy and paste some lines into this file, from my '''Writer''' document, which I had saved earlier. |
− | + | ||
− | '''Writer''' document, which I had saved earlier. | + | |
|- | |- | ||
Line 182: | Line 171: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Highlight''' Changes not staged for commit''' | | style="border:1pt solid #000000;padding:0.097cm;"| Highlight''' Changes not staged for commit''' | ||
| style="border:1pt solid #000000;padding:0.097cm;"| We can understand that our changes are not staged yet. | | style="border:1pt solid #000000;padding:0.097cm;"| We can understand that our changes are not staged yet. | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 235: | Line 221: | ||
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000000;padding:0.097cm;"| Highlight''' Stashed mypage.html''' and''' chapter-three''' | | style="background-color:#ffffff;border:1pt solid #000000;padding:0.097cm;"| Highlight''' Stashed mypage.html''' and''' chapter-three''' | ||
− | | style="background-color:#ffffff;border:1pt solid #000000;padding:0.097cm;"| On the terminal, the''' stash''' name and the''' branch''' name where the''' stash''' is created, is displayed. | + | | style="background-color:#ffffff;border:1pt solid #000000;padding:0.097cm;"| On the '''terminal''', the''' stash''' name and the''' branch''' name where the''' stash''' is created, is displayed. |
|- | |- | ||
Line 242: | Line 228: | ||
Highlight''' “nothing to commit”''' | Highlight''' “nothing to commit”''' | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| We will check the''' Git status''' by typing''' git space status'''. | + | | style="border:1pt solid #000000;padding:0.097cm;"| We will check the''' Git status''' by typing |
+ | |||
+ | ''' git space status'''. | ||
Line 287: | Line 275: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Type''' git status''' and press''' Enter''' | | style="border:1pt solid #000000;padding:0.097cm;"| Type''' git status''' and press''' Enter''' | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Let's check the''' Git status''' by typing''' git space status'''. | + | | style="border:1pt solid #000000;padding:0.097cm;"| Let's check the''' Git status''' by typing |
+ | |||
+ | ''' git space status'''. | ||
|- | |- | ||
Line 294: | Line 284: | ||
Type''' git stash''' and press''' Enter''' | Type''' git stash''' and press''' Enter''' | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Say, for example, in''' stash''' I want to save | + | | style="border:1pt solid #000000;padding:0.097cm;"| Say, for example, in''' stash''' I want to save these changes in another way. |
Line 538: | Line 528: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Let us summarize. | | style="border:1pt solid #000000;padding:0.097cm;"| Let us summarize. | ||
− | |||
In this tutorial, we have learnt about '''Stashing.''' | In this tutorial, we have learnt about '''Stashing.''' | ||
Line 544: | Line 533: | ||
We also learnt how to | We also learnt how to | ||
− | |||
* Create a''' stash''' | * Create a''' stash''' | ||
* Apply a''' stash''' and | * Apply a''' stash''' and | ||
* Clean''' '''a '''stash''' | * Clean''' '''a '''stash''' | ||
− | |||
− | |||
|- | |- |
Latest revision as of 19:59, 13 September 2015
Title of script: Stashing and Cleaning
Author: Priya K
Keywords: Video tutorial, stashing, save stash, delete stash, save temporary changes, stash pop, stash drop, stash apply, stash clear
|
|
Slide 1:
Stashing and Cleaning in Git |
Welcome to the spoken tutorial on stashing and cleaning in Git. |
Slide 2:Learning Objectives
|
In this tutorial, we will learn about stashing.
|
Slide 3:
System requirement
|
To record this tutorial, I am using
You can use any editor of your choice. |
Slide 4:
Pre-requisites
|
To follow this tutorial
|
Let us learn about stashing. | |
Slide 5:
Stashing |
|
Recall that we already came across the term stash earlier in this tutorial series.
| |
Press Ctrl+Alt+T to open the terminal | Let us begin by opening the terminal. |
We will open our Git repository mywebpage which we created earlier. | |
Type cd mywebpage and press Enter | Type cd space mywebpage and press Enter. |
I will continue to use html files for demonstration.
| |
From here onwards, please remember to press the Enter key after typing every command on the terminal. | |
Type git branch and press Enter | First we will check the branch list by typing
git space branch |
Highlight chapter-three | I have already created a branch named chapter-three.
And I have done a commit inside it, for demonstration purpose. Please make sure that you also create a new branch and make a commit inside it. |
Type git branch chapter-three and press Enter | We will go into the branch chapter-three by typing
git space checkout space chapter-three |
Type git log --oneline and press Enter
|
Let’s check the Git log.
|
Type ls and press Enter
|
Let’s check the folder content by typing ls
|
Highlight mypage.html
|
Now, we’ll make some changes on the file mypage.html
gedit space mypage.html space ampersand. |
Copy and paste some lines | I will copy and paste some lines into this file, from my Writer document, which I had saved earlier. |
Save and close the file | Then save and close the file. |
Type git status and press Enter | To check the Git status, type git space status |
Highlight Changes not staged for commit | We can understand that our changes are not staged yet. |
When we work in a big project, we may need to switch branches frequently. | |
Type git checkout master and press Enter | Now, let’s say, we want to go back to our master branch to work on something else.
|
Highlight “commit your changes or stash them” | This error shows that we can't switch back to other branches without committing the changes. |
I don't want to commit the changes right now, as my work is just half-done. | |
Type git checkout --force master
Highlight --force |
If we will forcefully exit this branch using the hyphen hyphen force flag, the changes will get discarded. |
Highlight stash | But what if I want to save the changes temporarily?
|
Type git stash save “ Stashed mypage.html” | We can save the changes temporarily by typing
git space stash space save space within double quotes “Stashed mypage.html” |
Highlight Stashed mypage.html and press Enter | Here “Stashed mypage.html” is the stash name I have given.
|
Highlight Stashed mypage.html and chapter-three | On the terminal, the stash name and the branch name where the stash is created, is displayed. |
Type git status and press Enter
|
We will check the Git status by typing
git space status.
So we can switch branches now.
|
Type git checkout master and press Enter | Now let's try to go into master branch by typing
git space checkout space master.
|
Type git checkout chapter-three and press Enter | Next, let us see another way of stashing.
git space checkout space chapter-three. |
Type gedit history.html & and press Enter | Now I will edit the file history.html.
|
Copy and paste the content | I will add some lines from my Writer document here. |
Save and close the file | Then save and close the file. |
Type git status and press Enter | Let's check the Git status by typing
git space status. |
Highlight modified: history.html
|
Say, for example, in stash I want to save these changes in another way.
|
Highlight the stash name | Note that we didn't give the stash name here.
|
Type git log --oneline and press Enter | Next, we will check whether the stash name and the latest commit are same.
|
Type git stash list and press Enter | To check the stash list, type git space stash space list. |
Highlight the latest commit from git log
Highlight the latest stash from stash list |
You can see that the latest commit and the latest stash name are same. |
Highlight “stash@{0}: WIP on chapter-three: c56658b Initial commit in chapter-three branch ” | Note that the latest stash is listed first.
|
Highlight the stash@{0} | This is the stash id which will be generated automatically. |
I will create one more stash for demonstration purpose. | |
Type gedit story.html & and press Enter | For that, I will edit the file story.html.
|
Add some lines | I will add some lines in the file story.html. |
Save and close the file | Then save and close the file. |
Type git stash save “ Stashed story.html” and press Enter | Now I will save the changes in a stash.
|
Type git stash list and press Enter | Let's check the stash list by typing git space stash space list. |
Highlight the stashes | We can see that now we have three stashes in the chapter-three branch.
|
In certain situations, we may not remember what changes we have saved in the stashes. | |
Let us see how to check it. | |
Highlight stash@{0}
|
Say, for example, I want to see the details of stash@{0}.
|
Highlight story.html changes | We can see the changes of story.html.
|
Next we will continue to work on the stashed files.
| |
Type git stash list and press Enter | To check the stash list, type git space stash space list. |
Highlight stash@{1} | For example, now we will apply the stash@{1}. |
Type git stash apply stash@{1} | To do so, type git space stash space apply space stash @ (at the rate symbol) within curly brackets one. |
Highlight stash@{1}
Highlight stash@{0} and press Enter |
If you don't mention the stash id, the latest stash (i.e) stash@{0} will be applied. |
Highlight “modified file: history.html” | You can see that our stash is applied successfully. |
Type git stash list and press Enter | Let's check the stash list by typing git space stash space list. |
We can see the stash@{1} still in the list and this may lead to confusion in future.
| |
Highlight stash@{1}
Type git stash drop stash@{1} and press Enter |
To delete the stash@{1}, type
git space stash space drop space stash@ (at the rate symbol) within curly brackets one. |
Type git stash list and press Enter | To check the stash list, type git space stash space list. |
Highlight “stash@{1}: WIP on chapter-three: c56658b Initial commit in chapter-three branch”
|
We can see that our stash@{1} is removed.
|
Type git stash pop and press Enter | Now, we will learn to apply a stash in another way.
|
Highlight stash@{0}
Highlight “modified: story.html” |
We can see that our stash@{0} is applied. |
Highlight stash@{0} from stash list | So, if we use stash pop command, the most recent stash (i.e) stash@{0} will be applied. |
Type git stash list and press Enter | Again we will check the stash list by typing
git space stash space list. |
Highlight “stash@{0}: On chapter-three: Stashed story.html”
Highlight “stash@{0}: On chapter-three: Stashed mypage.html” |
Now we can see that stash@{0} is removed.
|
Highlight “stash pop”
Highlight dropped stash@{0} |
So the stash pop command will apply the stash@{0} and delete it automatically.
|
Next we will learn how to remove all the stashes at once. | |
Type git stash clear and press Enter | To delete all the stashes from our repository, type
git space stash space clear. |
Type git stash list and press Enter | Again, we will check the stash list by typing
git space stash space list.
|
With this, we come to the end of this tutorial. | |
Slide 6:
Summary
|
Let us summarize.
In this tutorial, we have learnt about Stashing.
|
Slide 7:
Assignment
|
As an assignment
(Use – git stash pop)
(Hint – git stash clear) |
Slide 8:
Acknowledgement
|
The video at the following link summarises the Spoken Tutorial project.
|
Slide 9:
Spoken Tutorial Workshops
|
The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.
|
Slide 10:
Spoken Tutorial Project |
Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
|
This is Priya from IIT Bombay. Thanks for joining. |