Git combat Manual (iii): Stash and magical

Source: Internet
Author: User
0. Introduction
    • The picture shown in the tutorial is a github warehouse image, please visit the original address of a friend with slow speed
    • Take a look at the personal tech Station when you're free.

In the actual project development, always encounter the code to write half (unable to hit commit ), to open a new branch to fix bugs or increase the functionality of the situation. If you do not, the unmodified code is brought into a new branch that is created temporarily, and the code that is not finished is mixed with the code to be repaired, absolutely bitter. And Git stash is used to deal with this situation.

1. Initial knowledge git stash

stashIn English the meaning is: hide. In the process of GIT code management, it is also hiding the unfinished code, preventing it from interfering with the work of others or the new branch.

About git stash , common commands are as follows:

Command function
git stash Hide the current job site, at this point, git status the result isclean
git stash list View all hidden, the string preceding the colon of each line is the one that identifies this hiddenid
git stash apply <id> To re-display the hidden identity as ID
git stash drop <id> git applyAfter you hide, you need to manually delete the records in the list
2. Application and actual combat

Suppose: Just as I was writing a document on the master branch ( not completed, not submitted ), my colleague found that hello.py the script was problematic and the emergency report was repaired.

Receiving reports, subconsciously, is to open a debug branch to handle the bug. However, the current document is not completed, nature can not submit, and can not be submitted to the newly created Debug branch (this is determined, I can not:)). Currently, the status is as follows:

In order to achieve the goal, it is divided into the following steps:

    1. Hide changes: git stash :
    2. To create a new branch: git branch debug
    3. Fix the bug on the debug branch and add the modifications to log:
    4. Go back to the master branch, merge debug The branch's modifications, and delete the debug branch:
    5. Re-display the hidden and stash remove it from the stash list list:
    6. Then you can happily continue to do their own things!
3. Expand Reading

In the actual production process, will inevitably encounter a number of stash situation. At this point, their ID by default is: stash{0} , stash{1} , stash{2} ...

When we restore a stash and remove it from the Stash list, the ID of the stash record below it automatically becomes smaller to ensure that the ID is a contiguous natural sequence of 0 to N. therefore, when a stash is removed from the stash list, some stash IDs change . Here is a pit.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.