question:
Generally speaking, if you develop a requirement, you need to re-pull a git branch, which is also called a development branch, but it is conducive to the management and maintenance of requirements. At this time, it involves branch switching and submission, and there will be some problems in some scenarios:
- Scenario 1: When you are writing code in a development branch, suddenly there is a bug online that needs to be fixed urgently, and you need to switch back to the master branch for modification
- Scenario 2: When you develop two requirements at the same time, when one requirement is half developed, it is suspended for some reason and you have to develop the other requirement first
- Scenario 3: When you are halfway through the development of a requirement, you find that you have made a mistake in the branch, and you need to return the current branch to the state before the change, and at the same time restore the previously developed content on the new branch
In these scenarios, sometimes the functions have not been developed, or you don’t want to submit the code to the local or remote, because git has some color markings to facilitate the observation of file changes. At this time, you can either commit directly, go to the new branch to modify, and then come back to cancel the commit ; or use the staging code feature: Stash/Shelve.
solve:
The temporary storage code of git stash is local and will not be uploaded to the server. Instead of "cutting and pasting" first, put this part of the content on the "clipboard", and then "paste" it out when using it.
Steps:
1. Temporary storage
The first one : Git – Uncommitted Changes – Stash Changes
In the stash window, add note label information to the code temporarily stored in the current branch,
so that the code returns to the unmodified state.
The second type : Git – Uncommitted Changes – Shelve Changes
These two methods are similar, the specific differences are:
- Shelve is a built-in function of idea. It is more flexible and can freely choose the modification that needs to be temporarily saved.
- Stash is a function of git, which can only temporarily store all modifications together, and then restore them together
2. View
Git – Uncommitted Changes – Show Shelf
Here you can see the 3 temporary files of the project
It can also be viewed from here:
3. Recovery
When switching back to other branches and back again, restore the code.
The first one : Git – Uncommitted Changes – UnStash Changes
There will be all your temporary storage information here, and your stash on different branches will be displayed. Select the temporary storage information to restore, which is applicable to scenario 3. Check pop stash to delete this temporary storage after recovery.
Here drop is to delete a stash, and Clear is to delete all, do not operate! ! !
The second method : If it is troublesome, you can restore all from here with one click,
fill in the recovery information, check whether to delete the item after successful selection, etc.
END