I am working on one branch, and suddenly I have to switch to another branch to fix an urgent bug. The problem is the changes I make to the current branch is still a mess and I do not want to commit that and leave some scrappy commit message.
Is there any way I can save the current changes without commit?
The "git stash" command can help you to (temporarily but safely) store your uncommitted local changes - and leave you with a clean working copy.
You may switch branches with uncommitted changes in the work-tree if and only if said switching does not require clobbering those changes. That is—and please note that this is still simplified; there are some extra-difficult corner cases with staged git add s, git rm s and such—suppose you are on branch1 .
You must commit or stash those changes first before switching branches. You can think of stash as a drawer to store uncommitted changes temporarily. Stashing allows you to put aside the “dirty” changes in your working tree and continue working on other things in a different branch on a clean slate.
Yes, you can use stash.
git stash
It will save any uncommitted stuff in a special area where you can get it back later using
git stash apply
You can see what is in the stash with
git stash list
Stash obviously works. I just want to propose that it is also a viable, if not better, option, to just commit whatever you have got, for the following reasons:
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