git bug Branch----temporary save live git stash

Source: Internet
Author: User

In software development, bugs are like a routine, with bugs that need to be fixed, and in Git, because the branches are so powerful, each bug is repaired by a new branch, after the repair, the branch is merged, and then the temporary branch is deleted.

When you receive a bug that fixes a code name of 119, it's natural to create a branch issue-119 to fix it, but the current work on Dev hasn't been submitted yet.

[Email protected] Mingw32/c/gitskill (Dev)
$ git status
On Branch Dev
Changes to be committed:
(use "Git reset HEAD <file> ..." to Unstage)

New File:hello.txt

Changes not staged for commit:
(use "git add <file> ..." To update what would be committed)
(use "Git checkout--<file> ..." to discard changes in working directory)

Modified:readme.txt

It is not that you do not want to submit, but the work to half, not to submit, it is expected to complete a half-day time, but you have to fix the bug within one hours, what to do?

Fortunately, Git also provides a stash feature that can "store" the current work site, and then continue to work after resuming the site:

[Email protected] Mingw32/c/gitskill (Dev)
$ git stash
Saved working directory and index state WIP on dev:4f4f23a Dev Commit
HEAD is now at 4F4F23A Dev commit

Now use git status to view the workspace, which is clean, so you can safely create a branch to fix the bug

[Email protected] Mingw32/c/gitskill (Dev)
$ git status
On Branch Dev
Nothing-to-commit, working directory clean

First determine which branch to fix the bug on, assuming that you need to fix it on the master branch to create a temporary branch from the master branch:

[Email protected] Mingw32/c/gitskill (Dev)
$ git Checkout Master
Switched to branch ' master '
Your branch is up-to-date with ' origin/master '.

[Email protected] Mingw32/c/gitskill (Master)
$ git checkout-b issue-119
Switched to a new branch ' issue-119 '

Fix bug Now, add "bug fix Complete" in Readme.txt

$ cat Readme.txt
Master Branch Content
Add Dev Branch Content
Merge test content on Master branch
Branch Merge Test

Merge of Dev branch--no-ff mode
Bug fix Complete

[Email protected] Mingw32/c/gitskill (issue-119)
$ git Add readme.txt

[Email protected] Mingw32/c/gitskill (issue-119)
$ git commit-m "bug 119 had fix"
[issue-119 B4d16ef] Bug 119 had fix
1 file changed, 1 insertion (+)

After the repair is complete, switch to the master branch and complete the merge, and finally delete the issue-119

[Email protected] Mingw32/c/gitskill (issue-119)
$ git Checkout Master
Switched to branch ' master '
Your branch is up-to-date with ' origin/master '.

[Email protected] Mingw32/c/gitskill (Master)
$ git merge--no-ff-m "merge bug fix 119" issue-119
Merge made by the ' recursive ' strategy.
Readme.txt | 1 +
1 file changed, 1 insertion (+)

[Email protected] Mingw32/c/gitskill (Master)
$ git branch-d issue-119
Deleted Branch issue-119 (was B4d16ef).

The bug has been fixed and it's time to get back to work on the Dev branch.

[Email protected] Mingw32/c/gitskill (Master)
$ git Checkout dev
Switched to branch ' Dev '

[Email protected] Mingw32/c/gitskill (Dev)
$ git status
On Branch Dev
Nothing-to-commit, working directory clean

The work area is clean, where has the work area just been saved? Use the Git stash List command to see:

[Email protected] Mingw32/c/gitskill (Dev)
$ git Stash list
[Email protected] {0}: WIP on dev:4f4f23a Dev Commit

Work site is still, git put stash content to somewhere, but need to restore, there are two ways:

1. With git stash apply recovery, but after recovery, stash content is not deleted, you need to use git stash drop to delete.

2. Use Git to stash pop, restore the stash content also deleted.

[Email protected] Mingw32/c/gitskill (Dev)
$ git Stash list
[Email protected] {0}: WIP on dev:4f4f23a Dev Commit

[Email protected] Mingw32/c/gitskill (Dev)
$ git stash apply [email protected]{0}
On Branch Dev
Changes to be committed:
(use "Git reset HEAD <file> ..." to Unstage)

New File:hello.txt

Changes not staged for commit:
(use "git add <file> ..." To update what would be committed)
(use "Git checkout--<file> ..." to discard changes in working directory)

Modified:readme.txt


[Email protected] Mingw32/c/gitskill (Dev)
$ git Stash list
[Email protected] {0}: WIP on dev:4f4f23a Dev Commit

[Email protected] Mingw32/c/gitskill (Dev)
$ git stash drop [email protected]{0}
Dropped [Email protected]{0} (8F8D8FBDDF55ED37D505EECA7371F78E705A4DAA)

[Email protected] Mingw32/c/gitskill (Dev)
$ git Stash list

To view the workspace:

[Email protected] Mingw32/c/gitskill (Dev)
$ git status
On Branch Dev
Changes to be committed:
(use "Git reset HEAD <file> ..." to Unstage)

New File:hello.txt

Changes not staged for commit:
(use "git add <file> ..." To update what would be committed)
(use "Git checkout--<file> ..." to discard changes in working directory)

We're back to fixing the bug.

Summary: When we fix a bug, we create a new bug branch to repair, then merge, and finally delete;

When the work on hand is not complete, first put the work site Git stash, and then go to fix the bug, repair, then git stash pop, back to the job site.

git bug Branch----temporary save live git stash

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.