current position:Home>Please commit your changes or stash them before you switch branches

Please commit your changes or stash them before you switch branches

2022-01-27 02:12:20 Carrot rabbit

Project scenario :
current Bug You haven't solved it yet , And they sent you a new one Bug, And this Bug Compared with what I'm thinking about now Bug It's easier to solve .
You want to solve the new Bug, But before Bug It's not settled yet and can't be submitted . What do I do ?

Problem description :
When we use it normally Git When switching branches , The following prompt appears ( Please commit your changes or hide them before switching branches )

Please commit your changes or stash them before you switch branches.


Solution :
1. Because the current branch dev Originally from master Derived from a branch . At this point, you have to switch from this branch to its main branch . Then you need to put the dev Changes on the branch cannot be switched until they are committed , But it's time to dev Not all modifications have been completed on the branch , You don't want to submit . Then you have to choose stash ( Deposit ) they ( What you changed on the current branch is not submitted commit The content of ).
So step one , Execute on the current branch git stash command . Save the current branch ,id by 46da77c5

2. This time git status command , Show nothing to submit , Then you can go to the main branch master Create and switch to a new branch to repair another Bug 了 .


3. Then revise that Bug Also after submission , It's time to go back dev Branch up and continue to modify the unfinished Bug.
perform git checkout dev Switch to dev Branch , This is the time to execute git status The command still shows that there is nothing to submit . After all, we have succeeded ahead and will dev Uncommitted changes to “ hide “ 了 , At this time , use $ git stash list Order to see us “ Storage ” A list of .

Will find id by   46da77c5 The stored items are in the list , We need to restore it , There are two ways :

One 、 use git stash apply Order recovery , But after recovery ,stash Content is not deleted , This time

$ git stash list command ,id by 46da77c5 The stored items will also be in the list , You need to use git stash drop To delete ;

Be careful : If there are multiple on one branch stash, If you need to restore the specified stash , You can add... At the end of the command id, Such as

$ git stash apply [email protected]{0}

Also delete the specified stash The project is executed as

$ git stash drop [email protected]{1} .

Two 、 use git stash pop command , Restore at the same time stash The contents of the storage list are also deleted . This time git stash list command ,id by 46da77c5 The stored items will not be in the list .

Check again at this time You will find that the previous changes still exist , And execute git status It will continue to show that there are uncommitted changes on the branch .
 

copyright notice
author[Carrot rabbit],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270212178560.html

Random recommended