{"id":30817,"date":"2022-07-24T14:17:08","date_gmt":"2022-07-24T14:17:08","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=30817"},"modified":"2022-12-23T05:48:04","modified_gmt":"2022-12-23T05:48:04","slug":"git-lab-exercise-assignment-git-stash-part-11","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/git-lab-exercise-assignment-git-stash-part-11\/","title":{"rendered":"Git Lab Exercise &#038; Assignment: Git Stash: Part &#8211; 11"},"content":{"rendered":"\n<p><strong>Often, when you\u2019ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don\u2019t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.<br><br>You can also put it somthing like this, Your code is in progress and suddenly a customer escalation comes. Because of this, you have to keep aside your new feature work for a few hours. You cannot commit your partial code and also cannot throw away your changes. So you need some temporary space, where you can store your partial changes and later on commit it.<br><br>Stashing takes the dirty state of your working directory \u2013 that is, your modified tracked files and staged changes \u2013 and saves it on a stack of unfinished changes that you can reapply at any time.<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">\r\n<span class=\"hljs-comment\"># Modify | Add  Some files in Git working directory<\/span>\r\n$ git status\r\nNow you want to <span class=\"hljs-keyword\">switch<\/span> branches, but you don\u2019t want to commit what you\u2019ve been working on yet; so you\u2019ll stash the changes. To push a <span class=\"hljs-keyword\">new<\/span> stash onto your stack, run git stash <span class=\"hljs-keyword\">or<\/span> git stash save:\r\n\r\n\r\n$ git stash\r\nYour working directory is clean:\r\n\r\n\r\n$ git status\r\nAt this point, you can easily <span class=\"hljs-keyword\">switch<\/span> branches <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-keyword\">do<\/span> work elsewhere; your changes are stored on your stack. To see which stashes you\u2019ve stored, you can <span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">git<\/span> <span class=\"hljs-title\">stash<\/span> <span class=\"hljs-title\">list<\/span>:\r\n\r\n\r\n$ <span class=\"hljs-title\">git<\/span> <span class=\"hljs-title\">stash<\/span> <span class=\"hljs-title\">list<\/span>\r\n<span class=\"hljs-title\">stash<\/span>@{0}: <span class=\"hljs-title\">WIP<\/span> <span class=\"hljs-title\">on<\/span> <span class=\"hljs-title\">master<\/span>: 049<span class=\"hljs-title\">d078<\/span> <span class=\"hljs-title\">added<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">index<\/span> <span class=\"hljs-title\">file<\/span>\r\n<span class=\"hljs-title\">stash<\/span>@{1}: <span class=\"hljs-title\">WIP<\/span> <span class=\"hljs-title\">on<\/span> <span class=\"hljs-title\">master<\/span>: <span class=\"hljs-title\">c264051<\/span> <span class=\"hljs-title\">Revert<\/span> \"<span class=\"hljs-title\">added<\/span> <span class=\"hljs-title\">file_size<\/span>\"\r\n<span class=\"hljs-title\">stash<\/span>@{2}: <span class=\"hljs-title\">WIP<\/span> <span class=\"hljs-title\">on<\/span> <span class=\"hljs-title\">master<\/span>: 21<span class=\"hljs-title\">d80a5<\/span> <span class=\"hljs-title\">added<\/span> <span class=\"hljs-title\">number<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">log<\/span>\r\n<span class=\"hljs-title\">If<\/span> <span class=\"hljs-title\">you<\/span> <span class=\"hljs-title\">want<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">apply<\/span> <span class=\"hljs-title\">one<\/span> <span class=\"hljs-title\">of<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">older<\/span> <span class=\"hljs-title\">stashes<\/span>, <span class=\"hljs-title\">you<\/span> <span class=\"hljs-title\">can<\/span> <span class=\"hljs-title\">specify<\/span> <span class=\"hljs-title\">it<\/span> <span class=\"hljs-title\">by<\/span> <span class=\"hljs-title\">naming<\/span> <span class=\"hljs-title\">it<\/span>, <span class=\"hljs-title\">like<\/span> <span class=\"hljs-title\">this<\/span>: <span class=\"hljs-title\">git<\/span> <span class=\"hljs-title\">stash<\/span> <span class=\"hljs-title\">apply<\/span> <span class=\"hljs-title\">stash<\/span>@{2}.\r\n\r\n\r\n$<span class=\"hljs-title\">git<\/span> <span class=\"hljs-title\">stash<\/span> <span class=\"hljs-title\">apply<\/span> <span class=\"hljs-title\">stash<\/span>@{2}\r\n<span class=\"hljs-title\">If<\/span> <span class=\"hljs-title\">you<\/span> <span class=\"hljs-title\">don<\/span>\u2019<span class=\"hljs-title\">t<\/span> <span class=\"hljs-title\">specify<\/span> <span class=\"hljs-title\">a<\/span> <span class=\"hljs-title\">stash<\/span>, <span class=\"hljs-title\">Git<\/span> <span class=\"hljs-title\">assumes<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">most<\/span> <span class=\"hljs-title\">recent<\/span> <span class=\"hljs-title\">stash<\/span> <span class=\"hljs-title\">and<\/span> <span class=\"hljs-title\">tries<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">apply<\/span> <span class=\"hljs-title\">it<\/span>:\r\n\r\n\r\n$ <span class=\"hljs-title\">git<\/span> <span class=\"hljs-title\">stash<\/span> <span class=\"hljs-title\">apply<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>","protected":false},"excerpt":{"rendered":"<p>Often, when you\u2019ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don\u2019t want to do a commit of half-done work just so you can get back to this point later. The answer&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-30817","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=30817"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30817\/revisions"}],"predecessor-version":[{"id":30818,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30817\/revisions\/30818"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=30817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=30817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=30817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}