
So, what do you do if you want to apply a set of stashed changes but don’t want to keep them around later? That’s where the pop parameter to git stash comes in. Run git stash list again and you’ll see that your previous set of changes still exists. If you’re ready to commit the changes now, use git add or git commit -a to stage and commit the changes to your branch.Īs we previously mentioned, apply doesn’t remove the list of changes from your stashed change list.

Git has restored your changes, but not in the exact working state you were in before they were stashed. " to discard changes in working directory) ➜ ExampleRepo git:(master) git stash apply Let’s see what happens when we use the command git stash apply. Let’s see it in action.Īgain, our working tree is clean. So, let’s say that you want to actually apply one of those changesets. To stop viewing changesets, press the q button. Use the space bar to page through the list of changesets. If you have stashed many changes, (END) will instead appear as (more). Git gives us a list of stashed change sets. The list of stashed changes will take control of your terminal and look something like WIP on master: 60ab63f Initial commit Unlike before, this will open an interactive list instead of just printing out our changes. ➜ ExampleRepo git:(master) git stash list This is the same repository we were working with earlier. Let’s look at it with an example to see how it works. That’s where the list parameter to the stash command comes in. When that’s the case, you need to be able to figure out which of your changes you’ve socked away. Git went through and cleaned up our changes. Your branch is up to date with 'origin/master'. Then, when we check our git status again, we’ll see that there’s nothing in our working tree. Saved working directory and index state WIP on master: 60ab63f Initial commit I’ve staged them all, so my git status looks like this: I have a repository that has some files added by my IDE. Let’s use an example repository to show just how this works. Boom! Your changes are stashed away and kept as a diff inside a special portion of your Git repository. You run the most basic stash command, git stash. You have a big list of tracked changes on a branch. Let’s dive into some of the most common variations of the command to see how they work and how you can use them. There are a few different ways you can use the git stash command to save your work without committing it. Then, when it comes time to open a pull request, you’ll be certain that your changes work, but you’ll also be certain that your pull request-as well as theirs-only contains the changes that it really needs. You can test out your changes in those branches to see if they fix the bug before committing them to your own branch. You can use git stash to apply your changes to those other branches without committing them. There are lots of good reasons to try to limit the size of a branch’s changeset.
#Git stash changes Patch
While that’s OK if you’re the primary person working on that branch, if you’re helping to patch a bug for some teammates you might not want to commit your changes to their branches, too. Merging modifies the history of the branch you’d be working on. This beats merging your branch into those branches. So, if you’re working on a patch for a particular bug, you could stash changes, then try to apply them to multiple feature branches to make sure that your fix works. One nice feature of git stash is that applying the changes doesn’t remove them from the list of stashed states. Later, you can apply those changes from a list of stashed changes-either on your current branch or on a different branch after you switch branches. What Is git stash?Īs we mentioned, git stash is a tool that removes the working changes from your current branch and saves them as a diff. But it does remove them from the current branch and return it to the state it was in the last time you committed.

In fact, Git saves them for you on your local computer for as long as you keep the repository on that hard drive.
#Git stash changes zip
Git calls this tool “ stash,” and it lets you take your current changes and magically zip them away from view. You need to switch to the release branch, but you don’t want to permanently include your changes on your current feature branch.įortunately, there’s a tool for that. You want to help them try to reproduce the bug, but your changes aren’t ready to commit. Someone on your team needs a hand troubleshooting a critical bug.


You’re heads-down on an important feature when your Slack notifications suddenly start pinging.
