InterviewSolution
| 1. |
Git Stash |
|
Answer» Sometimes in large codebases, there might be some cases when we do not want to commit our code, but at the same time don’t want to lose the unfinished code. This is where git stash comes into play. The git stash command is used to record the current state of the working directory and index in a stash. It stores the unfinished code in a stash and cleans the current branch from any uncommitted changes. Now, we can work on a clean working directory. If in the future, we again need to visit that code, we can simply use the stash and apply those changes back to the working repository. As shown below, using the command git stash, we can temporarily stash the changes we have made on the working copy and can work on something else. Later, when needed, we can git stash pop and again start working on it. How to stash changes in Git? The syntax for stashing is as follows: git stashSuppose, you are working on a website and the code is stored in a repository. Now let's say, you have some files named design.css and design.js. Now you want to stash these files so that you can again use them later, while you work on something else. Therefore, later you can use the git stash list command to view all the changes. Drop Stash In case, you no longer require a stash, you can delete it with the following command: git stash drop <stash_id>If you want to delete all the stashes, simply use: git stash clear |
|