$ git stash pop branch masterĭropped (9079b4ffdf46574701cffcd68eb4feba80ebcf72) In order to apply it and remove it from the stack, use pop instead. You may notice that after using the apply subcommand, the stash will still be on the stack. For example, to get the second stash, you would use the following: $ git stash apply branch master If there is a different stash you'd like to get instead, you can specify it using the identifier at the beginning of each line. The stashed work at the top of the list is what you'll get when using the apply command without any extra arguments. $ git stash WIP on master: 7513525 Fixed console WIP on master: 91f33cc Fixed output WIP on master: bbf6ef9 Initial WIP on master: bbf6ef9 Initial commit You're able to view this stack using the list subcommand. Technically, when you stash changes, Git puts the changes on a stack, which can then be pulled off in a LIFO (last in, first out) order. What if, for example, you end up needing to stash changes from your working directory multiple times? Luckily, stash allows you to do just that. As we tend to find out in our day-to-day programming, real-world use-cases aren't usually that simple. In the examples above, we used stash in the simplest context. $ git stash applyĪnd just like that, you have your changes back. We're back to where we started as if we never made the changes at all! Now you can go off and fix that bug.īut what about restoring your changes? To get them back, we can simply use the apply sub-command, which takes the last-stashed changes and puts them back into your working directory. To verify, look for changes using git status: $ git status Saved working directory and index state WIP on master: bbf6ef9 Initial commitĪs you can see, HEAD is now back to our last commit, which in this case is the initial commit. To avoid losing the current updates you've made, you can just stash the changes instead and get them back later without messing up your commit history. However, the changes aren't finished, and you need to switch to a different branch to quickly fix a bug before continuing on with the current feature. No changes added to commit (use "git add" and/or "git commit -a") " to discard changes in working directory) Let's say you're working on a new feature and you made some modifications to your code, and you now have one or more files with uncommitted modifications: $ git status The stash command takes the uncommitted changes in your working directory, both the updated tracked files and staged changes, and saves them. Luckily, Git provides a mechanism to handle cases like this through the command git stash. However, you don't want to lose the changes you've made already, but they're not yet ready to commit the updates since they're not finished. If you've been working with Git long enough, you've probably had times where you made changes to your codebase, but needed to switch branches or work with the latest working version of your code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |