【Software Testing】Git Practical Detailed Explanation-Branches are detailed, just read this article.,...


foreword

How does Git store data?

What Git saves is not the change or difference of the file, but a series of snapshots at different times;
when performing a commit operation, Git will save a commit object (commit object);
the commit object will contain a pointer to the snapshot of the temporary storage, and Contains the author's name and email address, the information entered when submitting, and a pointer to its parent object;

The commit object generated by the first commit has no parent object, the commit object generated by the normal commit operation has one parent object, and the commit object generated by merging multiple branches has multiple parent objects;

Practical example:
Suppose there is a working directory now, which contains three files to be staged and submitted; the
stage operation will calculate the checksum (SHA-1 hash algorithm) for each file;
then the current version will be The file snapshots are saved to the Git warehouse (Git uses blob objects to save them);
finally, the checksum is added to the staging area for submission;

git add README test.rb LICENSE
git commit -m 'The initial commit of my project'

Steps after executing git commit:
Git will first calculate the checksum of each subdirectory (in this case only the project root directory);
then these checksums are saved as tree objects in the Git warehouse;
the commit submission object contains the tree object Pointer, GIt can reproduce the saved snapshot when needed;

There are five objects in the Git repository
Three blob objects: save file snapshots
A tree object: record the directory structure and blob object index
A commit object: contain pointers to tree objects and all commit information

commit object and its tree structure

Submit again after making some changes, then the generated submission object this time will contain a pointer to the last submission object (parent object).

Multiple commit objects and their parents

The essence of Git's branch:
it is just a variable pointer pointing to the submission object;
Git's default branch name is master;
after each submission, the pointer of the master branch will point to the latest submission object;
the master branch will automatically submit to the move forward;

Branches and their commit history

Create a branch:
it just creates a new pointer for you to move
Create a testing branch

git branch testing

This creates a pointer on the commit object that is currently in

two branches pointing to the same commit history

How does Git know which branch it is currently on?
It has a special pointer called HEAD;
in Git, it is a pointer to the current local branch;
here the local is currently the master branch, because the git branch command only creates a new branch and does not automatically switch to the new go in the branch;

switch branch

Two ways:

git checkout <分支名>
git switch <分支名>
git checkout testing

This way HEAD points to testing

Practical examples:

polo@B-J5D1MD6R-2312 watermarker % git checkout newtest2
M    test.py
A    test1..3.txt
A    test1.txt
D    test111.txt
A    test3.txt
切换到分支 'newtest2'
polo@B-J5D1MD6R-2312 watermarker % git log
commit 6652c6d6c439cb23ef6aaff79eeccbf3213a9a0b (HEAD -> newtest2, tag: 1.2, origin, newtest3)

Check the commit history after switching branches

It can be seen that there are three branches pointing to the latest submission object: origin, newtest2, newtest3, and the branch pointed to by the current HEAD is newtest2, because it has just been switched to newtest2

HEAD points to the current branch

So, what benefits will such an implementation bring us? Modify and submit again

vim test.rb
git commit -a -m 'made a change' 

The testing branch will move forward, but the master branch will not, because every time git commit submits new content, only the branch pointed to by HEAD will automatically move forward, and other branches will not move

The HEAD branch automatically moves forward with the commit operation to see
Switch back to the master branch
git checkout master

Did two things
HEAD points back to the master branch
Reverting the working directory to the snapshot content (old content) pointed to by the master branch
is equivalent to ignoring the modifications made by the testing branch
Important: Switching branches will change the files in the working directory

When checkout, HEAD follows

Revise and submit again

vim test.rb
git commit -a -m 'made other changes'

There is a branch fork in the current project, because some new content is submitted on the master branch, so a new submission object will be generated

For different branches, you can work on different content on it, and then merge in the future. The only commands you need to merge are: branch, checkout, commit

Project fork history

git log --oneline --decorate --graph --all 

It will output your commit history, the pointing of each branch and the branch of the project

git log --oneline --decorate --graph --all
* c2b9e (HEAD, master) Made other changes
| * 87ab2 (testing) Made a change
|/
* f30ab Add feature #32 - ability to add new formats to the central interface
* 34ac2 Fix bug #1328 - stack overflow under certain conditions
* 98ca9 initial commit of my project
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)

As long as you have a dream in your heart, you can climb endless peaks; as long as you move forward bravely, you can create your own brilliance. Not afraid of hardships and difficulties, the power of struggle will light up every corner of life, let us pursue the light of our dreams without hesitation!

Only unremitting efforts can create brilliance; only persistent struggle can chase dreams; only the determination to go forward can create miracles. Believe in yourself, you can conquer everything!

Only by constantly working hard can we surpass ourselves; only by persistently persisting can we welcome a brilliant life. No matter how many difficulties and setbacks you encounter, believe in your potential and go forward bravely, and you will eventually gain your success and glory!

Guess you like

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