Description
This tutorial is carried out in the order of git online exercises . The command operations of the online test are implemented in IDEA, and the development tools are used to implement all the operations in the online exercises.
You can combine git online exercises to learn this tutorial, first learn git commands online, and then implement the same operations in IDEA.
New test project
Create a new Empty Project: git-test1
Create a new Java Module: demo1
Create a new class
package test;
public class Test1 {
public static void main(String[] args) {
System.out.println(1);
}
}
Create a local warehouse
Set the project directory git-test1 as the local warehouse directory
Initial submission
View the commit history in the git tool window
Submit operation
Second submission
Add a sentence to print
package test;
public class Test1 {
public static void main(String[] args) {
System.out.println(1);
System.out.println(2);
}
}
Press ctrl+k to execute the submit operation
Check the submission history, you can see that there were two submissions
The above submission history is compared to the structure diagram of learngitbranching.js.org
Third and fourth submission
Perform the following two steps:
- Add the statement that prints 3 and submit
- Add a statement that prints 4 and submit
The above submission history is compared to the structure diagram of learngitbranching.js.org
Reset to the second commit
In order to continue the next exercise, first reset the submission history
After reset, only the first two commits
Branch merge-merge
Ready to submit structure
Create a new bugFix branch
If you check the Checkout branch
option, it will automatically switch to the new branch after creating a new branch
Now, the master branch, bugFix branch and HEAD are all merged in the last commit position
Make a commit to the bugFix branch
We have switched to the bugFix branch in the previous step. Now add a sentence to print and submit on this branch. After submission, the bugFix branch moved forward, but the master branch remained at the previous step
The above submission history is compared to the structure diagram of learngitbranching.js.org
Switch to master branch
In the lower right corner of the IDEA window, click the bugFix branch and switch to the master branch in the menu
Now switch to master, HEAD represents the current commit location
The above commit history is compared to the structure diagram of learngitbranching.js.org . The
asterisk indicates HEAD.
Make a commit to the master branch
Add a sentence to print 0 and submit at the front . Now, the master has also taken a step forward
The above submission history is compared to the structure diagram of learngitbranching.js.org
Merge branch-merge the bufFix branch to master
We are now in the master branch, click on the master branch in the lower right corner, and find the bugFix branch in the menu to merge with the master
Now, the code of bugFix is merged into master, and a new commit is generated on the master branch
The above submission history is compared to the structure diagram of learngitbranching.js.org
Try to merge the master branch to the bugFix branch and what will happen
Switch to the bugFix branch
Select master to merge to the bugFix branch
Just simply moved the bugFix to the master
The above submission history is compared to the structure diagram of learngitbranching.js.org
Reset to the second commit
Switch to the master branch
Reset to the second commit
Delete the bugFix branch
After reset, only the first two commits
The above submission history is compared to the structure diagram of learngitbranching.js.org
Use rebase to merge branches
Ready to submit structure
Create a bugFix branch and submit to it once
In the bugFix branch, add print 3 and make a commit. bugFix is a step forward
Switch to master and perform a commit to master
In the above add print and submit a 0, master a step forward
The above submission history is compared to the structure diagram of learngitbranching.js.org
Move bugFix to the master branch
With the rebase operation, you can move the submission of bugFix to the master branch to form a continuous submission record.
Switch to the bugFix branch
Under the bugFix branch, right-click the master branch and select the rebase operation from the menu
After rebase, bufFix moved to the master branch to form a continuous commit record, and the code was merged
The above submission history is compared to the structure diagram of learngitbranching.js.org