Git Bug Branch

Source: Internet
Author: User

Bug Branch

In software development, bugs are like the norm. With bugs that need to be fixed, in git, because branches are so powerful, each bug can be repaired by a new temporary branch, repaired, merged, and then removed by the temporary branch.

When you receive a task to fix a bug with a code number of 101, it is natural that you want to create a branch issue-101 to fix it, but, and so on, the work that is currently in dev progress has not yet been submitted:

$ git status# On branch dev# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)## new file: hello.py## Changes not staged for commit:# (use "git add <file>..." to update what will 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 only half of the work, not submitted, it is expected to be completed in 1 days. However, the bug must be fixed within two hours, what should I do?

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

$ git stashSaved working directory and index state WIP on dev: 6224937 add mergeHEAD is now at 6224937 add merge

Now, with the git status view workspace, it's clean (unless you have a file that's not managed by git), so you can safely create a branch to fix the bug.

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

$ git checkout masterSwitched to branch ‘master‘Your branch is ahead of ‘origin/master‘ by 6 commits.$ git checkout -b issue-101Switched to a new branch ‘issue-101‘

Now fix the bug and need to change "Git is free software ..." to "Git is a free software ..." and then submit:

$ git add readme.txt $ git commit -m "fix bug 101"[issue-101 cc17032] fix bug 101 1 file changed, 1 insertion(+), 1 deletion(-)

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

$ git checkout masterSwitched to branch ‘master‘Your branch is ahead of ‘origin/master‘ by 2 commits.$ git merge --no-ff -m "merged bug fix 101" issue-101Merge made by the ‘recursive‘ strategy. readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)$ git branch -d issue-101Deleted branch issue-101 (was cc17032).

Great, the original two-hour bug fix took only 5 minutes! Now it's time to go back to dev the branch and work!

$ git checkout devSwitched to branch ‘dev‘$ git status# On branch devnothing to commit (working directory clean)

The work area is clean, where did you save the work site just now? Take a git stash list look at the command:

$ git stash list[email protected]{0}: WIP on dev: 6224937 add merge

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

One is to use git stash apply recovery, but after recovery, stash content does not delete, you need git stash drop to use to delete;

Another way is to use git stash pop , restore the stash content also deleted:

$ git stash pop# On branch dev# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)## new file: hello.py## Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: readme.txt#Dropped refs/[email protected]{0} (f624f8e5f082f2df2bed8a4e09c12fd2943bdd40)

git stash listIf you look at it again, you won't see any stash content:

$ git stash list

You can stash multiple times, restore the time, first with git stash list view, then restore the specified stash, with the command:

$ git stash apply [email protected]{0}
Summary

When fixing a bug, we will fix it by creating a new bug branch, then merging and finally deleting;

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

Git Bug Branch

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.