{"id":4184,"date":"2020-09-01T17:31:42","date_gmt":"2020-09-01T18:01:42","guid":{"rendered":"https:\/\/ultering.com\/it4us\/?p=4184"},"modified":"2021-01-21T15:30:01","modified_gmt":"2021-01-21T16:00:01","slug":"git-i-do-love-git-stash-super-hero-when-things-go-wrong","status":"publish","type":"post","link":"https:\/\/ultering.com\/it4us\/?p=4184","title":{"rendered":"GIT: I do love Git stash &#8211; Super hero when things go wrong"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 counter-hierarchy ez-toc-counter ez-toc-white ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a152b749d753\" class=\"ez-toc-cssicon-toggle-label\"><span class><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\" \/><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\" \/><\/svg><\/span><\/span><\/label><input type=\"checkbox\" id=\"ez-toc-cssicon-toggle-item-6a152b749d753\" checked aria-label=\"Toggle\"><nav><ul class=\"ez-toc-list ez-toc-list-level-1 \"><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ultering.com\/it4us\/?p=4184\/#SCENARIO\">SCENARIO<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ultering.com\/it4us\/?p=4184\/#HOW_TO_SAVE_TIME_WHEN_THINGS_GO_WRONG\">HOW TO SAVE TIME WHEN THINGS GO WRONG?<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ultering.com\/it4us\/?p=4184\/#RESTORING_TO_BEGIN_AGAIN_WHEN_THIS_APPROACH_IS_THE_BEST_CHOICE\">RESTORING TO BEGIN AGAIN WHEN THIS APPROACH IS THE BEST CHOICE<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ultering.com\/it4us\/?p=4184\/#WHAT_ELSE_GIT_STASH_DOES\">WHAT ELSE GIT STASH DOES?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"SCENARIO\"><\/span><span style=\"font-size: 14pt;\">SCENARIO<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">Node.js project using Angular, etc.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">Usually, manually copying a project like an example above may take a very long time.&nbsp;<\/span><\/p>\n<p><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">Making synced snapshots using a sync tool is a better approach.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">A much better alternative is considering using a versioning tool.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">I chose Git.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">Probably, you may apply the concepts suggested here using another versioning tool that provides similar features as that Git provides.<\/span><\/p>\n<h2><span style=\"font-size: 14pt;\"><strong><br>\nHOW TO SAVE TIME WHEN THINGS GO WRONG?<\/strong><\/span><\/h2>\n<h2><span style=\"font-size: 14pt;\"><noscript><img decoding=\"async\" class src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/uninstall_complete.gif\" alt width=\"360\" height=\"240\"><\/noscript><img decoding=\"async\" class=\" lazyload\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20360%20240%22%3E%3C%2Fsvg%3E\" alt width=\"360\" height=\"240\" data-src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/uninstall_complete.gif\"><\/span><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">Just using Git without a strategy is not enough.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">For simple things, it may suffice. Unfortunately, most of the time, simple things don&#8217;t require versioning control.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">Here you get my recipe! \ud83d\ude42<\/span><\/p>\n<ol>\n<li><span style=\"font-size: 14pt;\" data-preserver-spaces=\"true\">Create a tracking file.<br>\nTake note in a .txt file, or whatever, of the main things done in the project.<br>\n.<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">Before an important operation, always commit your project.<\/span><br>\n<span style=\"font-size: 14pt;\">After the commit, take note of the commit revision number in your tracking file.<\/span><br>\n<span style=\"font-size: 14pt;\">This procedure will help to remember what each commit has in details, what you&#8217;ve done, what you get if you checkout to that revision number.<\/span><br>\n<span style=\"font-size: 14pt;\">Important operations are those that may screw your application.<\/span><br>\n<span style=\"font-size: 14pt;\">Examples:<\/span><br>\n<span style=\"font-size: 14pt;\">&#8211; installing a new package or library.<\/span><br>\n<span style=\"font-size: 14pt;\">&#8211; performing a long configuration including many steps.<\/span><br>\n<span style=\"font-size: 14pt;\">&#8211; creating a new module that it is shared with others.<\/span><br>\n<span style=\"font-size: 14pt;\">&#8211; and all those procedures involving many files, classes and configuration files.<\/span><br>\n<span style=\"font-size: 14pt;\">.<\/span><\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"RESTORING_TO_BEGIN_AGAIN_WHEN_THIS_APPROACH_IS_THE_BEST_CHOICE\"><\/span><span style=\"font-size: 14pt;\">RESTORING TO BEGIN AGAIN WHEN THIS APPROACH IS THE BEST CHOICE<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-size: 14pt;\">For example, you are supposed to create a new component.<\/span><br>\n<span style=\"font-size: 14pt;\">First, make sure that your application is running stable.<\/span><br>\n<span style=\"font-size: 14pt;\">Commit it and take note.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">&nbsp;<\/span><br>\n<span style=\"font-size: 14pt;\">&nbsp;Example using an Angular project:<\/span><\/p>\n<p><noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-4209\" src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/git_tracking_control_example.jpg\" alt width=\"1252\" height=\"335\" srcset=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/git_tracking_control_example.jpg 1252w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/git_tracking_control_example-300x80.jpg 300w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/git_tracking_control_example-768x205.jpg 768w\" sizes=\"(max-width: 1252px) 100vw, 1252px\"><\/noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-4209 lazyload\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201252%20335%22%3E%3C%2Fsvg%3E\" alt width=\"1252\" height=\"335\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201252%20335%22%3E%3C%2Fsvg%3E 1252w\" sizes=\"(max-width: 1252px) 100vw, 1252px\" data-srcset=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/git_tracking_control_example.jpg 1252w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/git_tracking_control_example-300x80.jpg 300w, https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/git_tracking_control_example-768x205.jpg 768w\" data-src=\"https:\/\/ultering.com\/it4us\/wp-content\/uploads\/2020\/09\/git_tracking_control_example.jpg\"><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: 14pt;\">Using the example above, suppose that something went wrong during the task.<\/span><br>\n<span style=\"font-size: 14pt;\">You try to fix thinking that it is something fast to fix but the clock is ticking and your site still fails to work as it should.<\/span><br>\n<span style=\"font-size: 14pt;\">It comes two possibilities.<\/span><br>\n<span style=\"font-size: 14pt;\">One is to use your notes to recheck what you&#8217;ve done.<\/span><br>\n<span style=\"font-size: 14pt;\">Another, and most usual, is that you didn&#8217;t take note of detailed information, so the notes are not enough to lead you to a fast solution.<\/span><br>\n<span style=\"font-size: 14pt;\">Much better is beginning again from the previous state without loosing your current code or detaching the branch (when you commit the current state and checkout to the previous commit number).<\/span><br>\n<span style=\"font-size: 14pt;\"><br>\nIn this case, git stash is perfect!<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">You do:<\/span><br>\n<span style=\"font-size: 14pt;\"><em>git stash<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt;\">And everything comes to what it was before starting to work in your new task.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">After git stash, you may restart coding from the beginning saving too much time trying to find out what has gone wrong.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"WHAT_ELSE_GIT_STASH_DOES\"><\/span><span style=\"font-size: 14pt;\">WHAT ELSE GIT STASH DOES?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-size: 14pt;\">The previous code is preserved in a temporary copy working copy that you may re-apply later or not.<br>\n<\/span><br>\n<span style=\"font-size: 14pt;\">In the example above, we usually do not re-apply, but in other cases this command is very useful when you desire to pull information as if you hadn&#8217;t started coding.<br>\nTo do this, you stash, then you pull, and to re-apply your code you do&nbsp;&#8220;<em>git stash pop&#8221;<\/em>.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Get more detailed information at:<\/span><br>\n<span style=\"font-size: 14pt;\"><a href=\"https:\/\/www.atlassian.com\/git\/tutorials\/saving-changes\/git-stash\">bitbucket<\/a><br>\n<a href=\"https:\/\/git-scm.com\/docs\/git-stash\">git doc<\/a><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: 14pt;\">Enjoy an easier life!<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>SCENARIO Node.js project using Angular, etc. Usually, manually copying a project like an example above may take a very long time.&nbsp; Making synced snapshots using a sync tool is a better approach. A much better alternative is considering using a versioning tool. I chose Git. Probably, you may apply the concepts suggested here using another &#8230; <a href=\"https:\/\/ultering.com\/it4us\/?p=4184\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &#8220;GIT: I do love Git stash &#8211; Super hero when things go wrong&#8221;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[35],"tags":[],"class_list":["post-4184","post","type-post","status-publish","format-standard","hentry","category-versioning"],"_links":{"self":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/4184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4184"}],"version-history":[{"count":6,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/4184\/revisions"}],"predecessor-version":[{"id":4224,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/4184\/revisions\/4224"}],"wp:attachment":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}