How git stash Lets You Reset Your Project and Save the Changes

Rate this post
How git stash Lets You Reset Your Project and Save the Changes

Stashing allows you to preserve a copy of changes you’ve made to a repository without committing them.

It’s helpful for moving contexts, particularly when transitioning between various problems or tasks on the same project.

Basic Operation of git stash

When dealing with parallel lines of work, you may utilize git stash to simplify your workflow. Assume you’re working on a long-running job that requires updates to your local working copy. Then something critical arises that need immediate attention.

The standard workflow for stashing changes is:

  1. Make local changes
  2. Stash local changes
  3. <other work>
  4. Reapply stashed changes

When you use the git stash [push] command to store modifications, git resets to HEAD. You may then continue working on whatever is necessary, committing to the repository as if you had never made the initial modifications.

When you’re through with whatever got you sidetracked in the first place, use git stash pop to apply your modifications and remove them from the stash. You may also use git stash apply to apply your modifications and retain them in the stash. This might be beneficial if you need to make changes to numerous branches rapidly.

Working With More Than One Stash

If you’re really busy, you may find yourself working on many jobs at the same time, and you may need to stow them all. Don’t worry, git stash is designed for situations like these.

Each time you use git stash push, you save a new set of modifications. To see everything you’ve stored, use git stash list. You’ll see something similar to this:

stash@{0}: WIP on main: 2fba62e first commit
stash@{1}: WIP on main: 2fba62e first commit

These messages aren’t particularly informative, but you can leave some hints for yourself by stashing with a custom message:

git stash push -m "third"

When you list now, you’ll see your custom message:

stash@{0}: On main: third
stash@{1}: WIP on main: 2fba62e first commit

Showing the Differences Between Diffs

Use git stash display to see what has changed in a stash. Without any other parameters, it will provide a diff summary for the most recent stash, which will look like this:

$ git stash show
README.md | 3 +++
1 file changed, 3 insertions(+)

You can also pass a stash id to query a specific entry:

git stash show stash@{0}

Creating a Branch From a Stash

You may decide that the modifications in a stash are important enough to warrant their own branch. If this is the case, use the branch command to establish a new branch from the stash:

git stash branch

Again, by default, this will function on the most current stash, but you may give a stash id if required. Git builds your new branch from the same place in the repository as the stash was created. The modifications from the cache are subsequently applied to your working copy.

  How to Send Audio in Facebook Messenger

Cleaning the Stash Up

There is no command “git unstash.” Drop: is used to eliminate a stash entry.

git stash drop

Again, the default is the most recent, but you may provide a stash id instead. If you wish to get rid of everything you’ve accumulated, perform the following command:

git stash clear

Use git stash for Temporary Lightweight Commits

Git stashes are much less powerful than entire repositories. However, they still provide a lot of important functionality on their own. Use stashes if you often need to swap branches in the midst of a project.

Stashing is just one component of git, which is a tool with a lot to offer.

You are looking for information, articles, knowledge about the topic How git stash Lets You Reset Your Project and Save the Changes on internet, you do not find the information you need! Here are the best content compiled and compiled by the achindutemple.org team, along with other related topics such as: How.

Similar Posts