Git stash

Time:2021-2-23

In the actual development work, you may encounter this situation:

When you’re in dev_ branch_ 1 branch work, suddenly interrupted, said that the master branch has an emergency bug, you need to fix it immediately

At this point, dev_ branch_ There are more than 20 uncommitted documents on branch 1. What should we do?

Write one temporarilyGit commit - M 'commit code', turn in more than 20 files without classification and description, and then switch to another branch immediately to solve the bug?

No, it’s unprofessional. In Git’s development mode, every commit should correspond to a feature / bug submission. When a commit contains multiple functions, it will increase your partner’s workload for later maintenance, such as others tracking bugs and locating code

So, in the case of the above situation, what should be the correct git operation?

The answer is stash operation

What is git stash?

All uncommitted modifications (workspace and buffer) can be saved to the stack for subsequent recovery of the current working directory

In the above scenario, how to use git stash?

In fact, in the above scenario, we need to do four steps

  1. Save unfinished work temporarily, but not commit it
  2. Switch to the master branch to solve the bug
  3. Switch back to your own dev branch
  4. Take the unfinished work in 1 back to the dev branch

So, which commands should be used to complete the four steps?

The answer is:

//Put the unfinished work on hold
git stash 

//Switch to the master branch to solve the bug
git checkout -b master

//Switch back to your own dev branch
git checkout -b dev

//Take the unfinished work in 1 back to the dev branch
git stash po

Next, please see the corresponding diagram of these four steps

Git stash

The above is the operation of GIT stash

Recommended Today

MySQL partition

MySQL partition Advantages of partitioning Store more data To optimize the query, only scan one or more necessary partitions. For count () and sum (), only summarize the partition statistics For data that is out of date or does not need to be saved, partitioning is faster Data queries are distributed across multiple disks to […]