[Software testing] Git combat - branch creation and merging (super fine finishing)


foreword

new branch

First, let's assume you're working on your project and have some commits already on the master branch.

In order to solve the problem, you want to create a new branch and switch to that branch at the same time, you can run a git checkout command with the -b parameter

$ git checkout -b iss53
Switched to a new branch "iss53"

It is shorthand for the following two commands

$ git branch iss53
$ git checkout iss53

Create a new branch pointer

Modify something on the iss53 branch and submit it, the branch will continue to move forward, because the branch has been checked out (that is, the HEAD pointer points to the iss53 branch)

$ vim index.html
$ git commit -a -m 'added a new footer [issue 53]'

Urgently insert an issue to be fixed

Suddenly an issue needs to be fixed urgently, it can not be mixed with the iss53 branch.
Operation steps:
git status Check whether there are uncommitted changes in the work area and temporary storage area under the iss53 branch, otherwise it will prevent git from switching branches;
switch to the master branch;
create a new hotfix branch and switch to it to fix the problem;

$ git checkout master
Switched to branch 'master'

At this time, Git will make the content of the working directory consistent with the content of the last commit on the master branch, and it will automatically add, delete, and modify files in the working directory

In order to fix the problem, create a new branch and work on it until the problem is fixed successfully

$ git checkout -b hotfix
Switched to a new branch 'hotfix'
$ vim index.html
$ git commit -a -m 'fixed the broken email address'
[hotfix 1fb7853] fixed the broken email address
 1 file changed, 2 insertions(+)

Merge the branch that fixes the problem to the master branch

After the problem is successfully fixed, you can merge the hotfix branch back to the master branch to deploy it online

$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast-forward
 index.html | 2 ++
 1 file changed, 2 insertions(+)
 

What is fast-forward?
The commit C4 pointed to by the branch hotfix to be merged is the direct successor of the commit C2 you are in, so Git will directly move the pointer forward

In other words, when trying to merge two branches, if you can go down one branch to reach the other branch, then when merging the two, Git will simply advance the pointer forward (the pointer moves to the right), because there is no conflict to be resolved in the merge operation in this case

Now, the latest modification is already in the commit snapshot pointed to by the master branch, and the release fix can be submitted

Delete the hotfix branch and go back to the iss53 branch to continue working

After the problem is solved, delete the temporary branch, because it is no longer needed, and the master branch also points to the same location

$ git branch -d hotfix
Deleted branch hotfix (3a0874c).

Go back to the iss53 branch and continue to work and submit

$ git checkout iss53
Switched to branch "iss53"
$ vim index.html
$ git commit -a -m 'finished the new footer [issue 53]'
[iss53 ad82d7a] finished the new footer [issue 53]
1 file changed, 1 insertion(+)

Note:
The work done on the hotfix branch is not included in the iss53 branch.
If you need to pull the changes made by the hotfix, you can use the git merge master command to merge the master branch into the iss53 branch, or you can wait until the iss53 branch completes its mission, and then merge it back into the master branch

branch iss53 merged

The work on the iss53 branch has been completed, go back to the master branch to merge the iss53 stuff

$ git checkout master
Switched to branch 'master'
$ git merge iss53
Merge made by the 'recursive' strategy.
index.html |    1 +
1 file changed, 1 insertion(+)

Merge made by the 'recursive' strategy.

Because the commit where the master branch is located is not a direct ancestor of the commit where the iss53 branch is located, Git has to do some extra work;
when this happens, Git will use the snapshots pointed to by the ends of the two branches (C4 and C5) and the common ancestor of these two branches (C2), and do a simple three-way merge;

merge commit

The difference from pushing the branch pointer forward before is that Git takes a new snapshot of the result of the three-way merge and automatically creates a new commit pointing to it. Its special feature is that it has more than one parent commit

Now that the changes have been merged in, the iss53 branch is no longer needed

$ git branch -d iss53

Merging branches when encountering conflicts

If different modifications are made to the same part of the same file in two different branches, Git will not be able to merge them cleanly; assuming that the modification of the
iss53 branch and the modification of the hotfix branch both involve the same part of the same file, a merge conflict will occur when merging them;

$ git merge iss53
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

Note:
At this point Git did the merge, but did not automatically create a new merge commit;
Git will pause and manually resolve the conflicts generated by the merge;
use the git status command to view those files that are in an unmerged state because they contain merge conflicts;

$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")

Unmerged paths:
  (use "git add <file>..." to mark resolution)

    both modified:      index.html

no changes added to commit (use "git add" and/or "git commit -a")

Any files that are pending resolution because they contain merge conflicts are marked with an unmerged state

Conflict identification
Git will add standard conflict resolution markers to conflicting files, which can quickly locate and resolve conflicts

<<<<<<< HEAD:index.html
<div id="footer">contact : [email protected]</div>
=======
<div id="footer">
 please contact us at [email protected]
</div>
>>>>>>> iss53:index.html

Graphical tools for resolving conflicts

If you want to use a graphical tool to resolve conflicts, you can run git mergetool, which will start a suitable visual merge tool for you, and walk you through the steps to resolve these conflicts:

$ git mergetool

This message is displayed because 'merge.tool' is not configured.
See 'git mergetool --tool-help' or 'git help config' for more details.
'git mergetool' will now attempt to use one of the following tools:
opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse diffmerge ecmerge p4merge araxis bc3 codecompare vimdiff emerge
Merging:
index.html

Normal merge conflict for 'index.html':
  {
    
    local}: modified file
  {
    
    remote}: modified file
Hit return to start merge resolution tool (opendiff):

View the merged status through git status

$ git status
On branch master
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:

    modified:   index.html

Submit the merged content through git commit

Merge branch 'iss53'

Conflicts:
    index.html
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
#    .git/MERGE_HEAD
# and try again.


# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# All conflicts fixed but you are still merging.
#
# Changes to be committed:
#    modified:   index.html
The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

Only by daring to chase your dreams can you make your life bloom with the most beautiful colors; only by working hard can you write your own glorious chapter. No fear of difficulties, keep moving forward, every step is the key to success, persistent struggle, will eventually reap a brilliant life.

Only by doing our best can we surpass the limit; only by not giving up can we pursue our dreams; only by persisting in struggle can we create brilliance. Believe in yourself, go forward bravely, the future success belongs to you!

Only by constantly surpassing ourselves can we pursue the footsteps of our dreams; only by persevering can we create a brilliant life; only by doing our best can we climb to the peak of life. Fight, brave soul, you will surely shine!

Guess you like

Origin blog.csdn.net/shuang_waiwai/article/details/131810015