“This is the 14th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

The vast sea of millions, thank you for this second you see here. I hope my article is helpful to you!

May you keep your love and go to the mountains and seas in the coming days!

Note: 😎 today we will learn new knowledge bai! In the process of work, you will inevitably encounter bugs, water days, iron bug, so how do you solve the bug in your work? What do you do if your code is sweating and a big bug comes in?

😙 Branch Management (key)

🥥 Bug branch

In real project development, bugs are a daily occurrence. But bugs need to be fixed, otherwise a project will have instability or greetings from all sides. 😅

In Git, because branches are so powerful, each Bug can be fixed with a new temporary branch, which is merged and then removed. When you receive an issue where the test girl has a bug code 66. You didn’t want to change it, or you wanted to wait until you had time to fix the Bug later, but the test girl kept pushing you.

In the end, you have to fix the Bug, and naturally you want to create a branch of Issue-66 to fix the Bug. Wait, want to create a branch to fix a Bug, but work currently in progress on Dev has not yet been committed:

  • Add heihei to hello.txt.

    heihei!
    Copy the code

  • You create a new file, write it to HelloGit, and add it to the repository.

    helloGit!
    ​
    $ git add git.txt
    Copy the code

  • So the state of your working directory is as follows:

    $ git status
    On branch dev
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    ​
            new file:   git.txt
    ​
    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:   hello.txt
    Copy the code

    Of course, it’s not that you don’t want to submit, it’s that you’re halfway through your work and can’t submit. But it is expected to take two or three days to finish. But what if the test only gives you two hours to fix the Bug?

    Fortunately, Git also provides a Git Stash feature that allows us to “stash” our current work site for later recovery:

    $git stash Saved Working Directory and index state WIP on dev: DDc0995Copy the code

    Your workspace is now clean (unless you have files managed by Git) with Git status, so you can safely create branches to fix bugs.

    $ git status
    On branch dev
    nothing to commit, working tree clean
    Copy the code
  • Pay attention to: If you use itgit stashWhen the workspace is not in effect, as it was the first time you viewed the workspace, you need to see if there is any new file code that has not been added to the workspace first. Git files that are not in Git version control cannot be usedgit stashSaved. So you should add the file to the workspace first, as to add to the workspace, how to undo the workspace, the previous also explained!

If you can’t find it, you can create a temporary branch from the master branch, assuming you need to fix the bug on the master branch:

$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)
​
$ git checkout -b issue-66
Switched to a new branch 'issue-66'
Copy the code

Now to fix the Bug, we need to find the location of the Bug and modify it. Now all you need is “Git is very nice software!” Git is very good software! And then submit:

$ git add  hello.txt
$ git commit -m "fix bug 66"
[issue-66 5a872c7] fix bug 66
 1 file changed, 1 insertion(+), 1 deletion(-)
Copy the code

When the fix is complete, switch to the Master branch, complete the merge, and finally remove the issue-66 branch:

$ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 4 commits. (use "git push" to publish your local commits) $ git merge issue-66 Updating ddc0995.. 5a872c7 Fast-forward hello.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Copy the code

The original workspace has not been moved, and the branch after fixing the Bug does not want, you can also delete it. The delete branch command was introduced earlier. And what was supposed to be a two-hour bug fix only took 5 minutes! 👨🦰 what to do now?

😆 hey hey, online secretly touch fish? Fishing is out of the question in this life. Fishing may be fun for a while, but eventually fishing will have to pay a price. How can you waste it when you’re getting paid to improve yourself? One can derive pleasure from work, and that is a great benefit. There’s only one thing on my mind right now, and that’s coding.

Now, it’s time to get back to work on the Dev branch!

$ git checkout dev
Switched to branch 'dev'
​
$ git status
On branch dev
nothing to commit, working tree clean
Copy the code

But but, uh, the workspace is clean. Where did I put my work scene? It’s not gone, is it? How do we get it back? Don’t worry, your husband won’t hurt you. Hey, hey, rattail juice.

Now let’s see with git Stash list:

$git stash list Stash @{0}: WIP on dev: ddc0995 Modify conflictCopy the code

The workspace is still there, it’s just that Git has stash content somewhere, but it needs to be restored. There are two ways to do this:

One is to restore with a Git Stash apply, but the stash content is not deleted. You need to remove it with a Git Stash pop.

Another way to do this is to use git Stash pop, which removes the stash content as well:

$ git stash pop
On branch dev
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
​
        new file:   git.txt
​
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:   hello.txt
​
Dropped refs/stash@{0} (07e1b06c2107a1b06046393c99fc418266ad271b)
​
$ git status
On branch dev
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
​
        new file:   git.txt
​
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:   hello.txt
Copy the code

If you look at the Git Stash list, you won’t see any stash content:

$ git stash list
Copy the code

You can do this multiple times with the git Stash list and then restore the specified stash with the following command:

$ git stash apply stash@{0}
Copy the code

Learning from this, 😜 will learn to fix bugs by creating new Bug branches to fix, then merge, and finally delete.

When the work in hand is not finished, first put a git stash on the work site, then go to fix the Bug, after fixing, then go back to the work site with a Git stash pop.

🌸 summary

I believe that you see here, today’s git tutorial should be simple for you! Do you know how to handle bug branches at work? This is not called bug solving, just teach to create bug branches to solve bugs.

Git Stash temporary buffer git Stash list View the buffer git Stash pop delete the bufferCopy the code

Let’s refuel together, too! I am not just, if there is any missing, wrong place, also welcome you to criticize in the comments of talent leaders! Of course, if this article is sure to help you a little bit, please kindly and lovely talent leaders give a thumblike 👍, save it, and welcome to follow ❤️❤️❤️ [favorite food of canned fish] 👍, thank you very much! If you like canned fish too! 💕 💕 💕

Here, the world is closed for today, good night! Although this article is over, I am still here, never finished. I will try to keep writing articles. The coming days are long, why fear the car yao ma slow!

Thank you all for seeing this! May you live up to your youth and have no regrets!