Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to Git Foundation (9) Git Branch Management

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Branch Management:

Branch command

Git branch # View branch list

Git branch-v # for a list of branches, in more detail

Git branch-a # View all branches and protect remote branches

Git branch-- merged # to see which branches have been merged into the current branch

Git branch-- no-merged # View all branches that are merged

Git branch-d # deletes specified branches (branches that have been merged and will not cause loss of work)

Git branch-D # forcibly delete the specified branch (use with caution, it may result in loss of work)

Workflow example:

Creation and merging of branches

Similar workflows may be used in real work, and you will go through the following steps:

1. Develop a website

2. To implement a new requirement, create a branch

3. Work on this branch

At this point, there is suddenly a serious bug that needs to be resolved, and you will deal with it as follows:

1. Switch to your online branch

2. Create a new branch for this urgent task and fix it in it

3. After the test passes, switch back to the online branch, then merge the repair branch, and finally push the changes to the online branch.

4. Switch back to the branch where you originally worked and continue to work

Git checkout-b iss53 # create and switch to the iss53 branch

Echo'#! / usr/bin/env python' > a.py # modify the contents of the file

Git commit-a-m 'test1' # submission

Git log-- pretty=oneline-- decorate # to view the branch status

Git checkout master # switch back to the master branch

Git checkout-b test # create and switch to the test branch

Echo'# coding:utf-8' > a.py # modify the contents of the file

Git commit-a-m 'testbranch2' # submission

Git checkout master # switch back to the master branch

Git merge test # merges the test branch into the master branch

Git branch-d test # Delete the test branch

Git checkout iss53 # switch Branch

Echo 'import os' > a.py # modify the contents of the file

Git commit-a-m 'v1' # submit

Git checkout master # switch back to the master branch

Git merge iss53 # conflicts arise because the different values of the same file are modified in different branches

Auto-merging a.py

CONFLICT (content): Merge conflict in a.py

Automatic merge failed; fix conflicts and then commit the result.

Git status # View conflicts

Git mergetool # opens mergetool to resolve conflicts, mergetool will enable the default text editor and lead you to resolve conflicts

Git status # check to see if the resolution is complete

Git add-A # will be followed by all files after resolution.

Git commit-m 'ok' # commit and merge branches

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report