Suppose the current commit is A, and then I create a new commit B, and then I make some changes in the working tree directory. Now I run git stash push. What does git stash push stash? Is it only the changes that I have made in the working tree directory since B was created, or also the changes that I made into commit B since A?
If I then checkout commit A, and run git stash pop, will that apply the changes that I made to the working directory after creating commit B, or also the changes that I made into commit B since A?
Does git stash push stash the changes to the last committed state (i.e. the differences between the current working tree directory and the last committed state), or stash just the current state?
According to the documentation:
Save your local modifications to a new stash entry and roll them back to HEAD (in the working tree and in the index). The part is optional and gives the description along with the stashed state.
For quickly making a snapshot, you can omit "push".
In other words, git stash push is the same as git stash.
Also in the documentation, git stash save has been deprecated in favor of git stash push.
When you run git stash, you stash any changes that haven't been committed, reverting your branch back to the latest commit. If you change branches and run git stash pop, Git will then apply your changes to the new branch.
However, git stash pop can fail if the two branches are out of sync. For example, the file FOO has been pushed to branch A, and git stash stashes a change to that file. Branch B doesn't contain FOO, so git stash pop will fail to apply your stash onto branch B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With