Git

Reapplying Stashed Changes

While working on Git, developers may need to save unnecessary changes somewhere for future use temporarily. Git provides the “Stash” mechanism to save untracked or uncommitted changes locally. Users can reapply the stashed changes whenever they need them. Moreover, Git commands are available to retrieve the changes stored in the stash.

This article will describe the method to reapply the stashed changes in Git.

How to Reapply/Restore Stashed Changes in Git?

To reapply the stashed changes in Git, the following are the two ways:

Method 1: Reapply Stashed Changes Utilizing “git stash pop” Command

To reapply the stash changes to the working directory and remove them from the stash stack, utilize the “git stash pop” command.

Step 1: Check Git Status

First, execute the below-provided command to view the current status of the repository:

$ git status

The below output indicates that the Git status is clear:

Step 2: View Stash Changes

Then, display the changes stored in the stash:

$ git stash show

It can be seen that two files are stashed:

Step 3: Reapply Stash Changes

Now, run the provided command to remove the changes from the stash and re-apply them to the working directory:

$ git stash pop

As you can see, the given command has reapplied the previously stashed changes to the repository:

Method 2: Reapply Stashed Changes Utilizing “git stash apply” Command

If users want to re-apply the stash changes and keep changes in the stash stack, the “git stash apply” command can be used:

$ git stash apply

We have explained the procedure of reapplying stashed changes in Git.

Conclusion

To reapply the stashed changes, two options can be utilized with the “git stash” command, such as the “apply” or “pop” options. The “git stash pop” command re-applies the stash modifications to the working directory and deletes them from the stash stack. While the “git stash apply” command re-applies the stash changes but keeps them in the stash stack. This article explained the methods to reapply stashed changes in Git.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.