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

Git branch create branch delete branch merge

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

Share

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

Git version 1.9.6 of this article

First, create branches and delete branches

Create branches, merge branches, and delete branches

Create a branch, git 3-way merge, and delete a branch

Git branch related commands

Git branch # lists how many branchgit branch new-branch # currently generates a new branch (name: new-branch), if not specified A copy of the current branch / master will be copied directly. Git branch new-branch master # New branch (new-branch) git branch new-branch v1 # generated by master (new-branch) git branch-d new-branch # Delete new-branchgit branch-D new-branch # force deletion of new-branchgit checkout-b new-branch test # to generate a new branch And switch past new-branch# related to remote repository git branch-r # list all Repository branchgit branch-a # list all branch

1. Create branches and delete branches

1.1.Create branch

1.2. switch to the new branch;Testbranch

During the handover, the HEAD execution changes as shown in the figure:

In other words, although HEAD points to Testbranch after switching, Testbranch, like master, points to the last commit.

Verify as follows:

HEAD after switching

Switch back to master, verify, and delete Testbranch

Delete the Testbranch, and the branch index file no longer exists.

2. Create branches, merge branches, and delete branches

2.1.View the last commit log of the current master; create a branch Testbranch

Modify code in the current branch, and commit to view the current commit log

Switch back to master, view commit log merge branches, view commit log, delete branch Testbranch, view commit log

Tips:

Why delete Testbranch after merging?

In the master branch, his corresponding final index is last commit

And in the Testbranch branch, his corresponding final index is his just commit, which we assume is B.

If we forcibly delete the branch Testbranch in the Master branch, then the commit of the Testbranch branch is invalid; so we need to merge the Testbranch first, delete it, and index it as shown in the figure:

You can see from the commit log above

3. Create branches, git 3-way merge, and delete branches

Ps: the branch is created above and submitted when the branch modifies the code,. What if the code is modified in the branch and the code is modified in master?

3.1.View master branch commit log, create Testbranch branch, view commit log, modify code twice, commit respectively, and view commit log

$echo "print\" Test1\ "> hello.pl$ git commit-am" test1 "$echo" print\ "Test2\" > > hello.pl$ git commit-am "test2"

Switch to master, view commit log;, modify code, and perform commit; to view commit log

Merge Testbranch; delete Testbranch

$git merge Testbranch$ git branch-d TestbranchDeleted branch Testbranch (was ec4c4ba).

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