![]() ![]() Saved working directory and index state WIP on my-feature: 66f3f3b Add colors file You can also carry over your stashed commits to a new feature branch or debugging branch by using git stash branch: $ git status Saved working directory and index state WIP on my-feature: 0d8deef delete colors Nothing added to commit but untracked files present (use "git add" to track) If the stashed file was not the problem, you can restore the stash. Leave all but the suspected bug file unstaged (code must be staged to be stashed), then you can stash that file and troubleshoot the issue. , which resets all uncommitted code.Īs another example of how to use Git stash: say you have some new files, one of which has a bug. If you decide not to commit your work once you have restored the stash, you can run git checkout. Git stash apply has applied the oldest stashed code, when we changed the colour of the text to red. $ git stash WIP on my-feature: 49ee696 Change text WIP on my-feature: 49ee696 Change text WIP on my-feature: 49ee696 Change text color Here is an example of stashing more than one commit and applying a different stash: $ git diff You can also apply a specific stash (if you have stashed more than once) by running git stash apply (the ‘1’ denotes the second before last stash). ![]() You can easily reapply the stashed content by running git stash apply. When you switch back to your branch and run git stash list you’ll see a list of stashes that look something like this: $ git stash WIP on my-feature: 49ee696 Change text color Now, you can safely change branches without losing your code or having a messy commit. Your branch now appears as it was when you made your last commit. Saved working directory and index state WIP on my-feature: 49ee696 Change text color It is not possible to push a stash to a remote repository, so a stash is just for your own personal use. Stashing is like saving a temporary local commit to your branch. When you run git stash, the uncommitted code disappears without being committed. No changes added to commit (use "git add" and/or "git commit -a")ĭiff -git a/css/common.scss b/css/common.scssįont-family: "Proxima Nova", Arial, sans-serif " to discard changes in working directory) Right now, your code looks like this: $ git status This can often happen if you are on your main branch, and you have forgotten to create a new branch for your feature. Then, for some reason, you suddenly need to attend to another task and have to switch branches. You’ve already made three neat and tidy commits, but you also have some uncommitted code that’s quite messy you won’t want to commit it without removing your debugging code first. How is this useful? Picture the following scenario: Git stash enables you to save your code without making a commit.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |