The current branch work site is now "stored".
$ git stash
stash
Function, you can "store" the current work site, and continue to work after the site is restored.
Each bug can be fixed with a new temporary branch, after which the branch is merged and the temporary branch is deleted.
First decide on which branch to fix the bug. Assuming it needs to be fixed on the master
branch, master
create a temporary branch from:
$ git checkout master
$ git checkout -b issue-101
Fix the bug, then submit:
$ git add readme.txt
$ git commit -m "fix bug 101"
After the fix is complete, switch to the master
branch, complete the merge, and finally delete issue-101
the branch:
$ git checkout master
$ git merge --no-ff -m "merged bug fix 101" issue-101
$ git branch -d issue-101
Then go back to dev
the branch to work:
$ git checkout dev
$ git status
$ git stash list
The work site is still there, and Git has stored the stash content somewhere, but it needs to be restored. There are two ways:
One is to use git stash apply
recovery, but after recovery, the stash content is not deleted, you need git stash drop
to delete it;
Another way is to use git stash pop
, and delete the stash content while restoring:
Check again git stash list
, you can't see any stash content:
$ git stash list
You can stash multiple times. When restoring, use git stash list
View first, and then restore the specified stash. Use the command:
$ git stash apply stash@{0}
Summarize:
When fixing bugs, we fix them by creating a new bug branch, then merge, and finally delete;
When the work at hand is not completed, visit the work site first git stash
, then fix the bug, and after the fix, go git stash pop
back to the work site.