Original: Taste of Little Sister (wechat official ID: XjjDog), welcome to share, please reserve the source.
A few days ago, someone in the company did git training. The lecture was so boring that the audience fell asleep. This reminds me of a great visual Git learning tool. With this tool, git trainers in the company can be laid off.
This article describes the tool in detail, with the address given at the end.
Git is already a must-have skill for programmers, but it has barriers. A lot of times, just knowing pull, push, commit, etc. doesn’t solve the problem, especially when there are conflicts.
Depending on the Git instructions you enter, this process is all animated. You can easily see how the flow of data in your Git repository is changing by pointing at the arrows.
Welcome to star: github.com/xjjdog/bcma… . It includes ToB complex business, Internet high concurrency business, cache applications; DDD, microservices guidance. Model driven, data driven. Understand the evolution of large-scale services, coding skills, Learning Linux, performance tuning. Docker/ K8S power, monitoring, log collection, middleware learning. Front-end technology, back-end practices, etc. Main technology: SpringBoot+JPA+Mybatis-plus+Antd+Vue3.
1. Submit relevant
Below is an animation after committing twice. You can see that the version has changed twice and is the same color.
git commit
git commit
Copy the code
Below is the execution of the new branch instruction. By specifying the b parameter, the branch can be created automatically when it does not exist.
git checkout -b bugFix
Copy the code
We now create a new branch, bugFix, and merge bugFix into main using the merge command after committing the code once for main and bugFix respectively.
git checkout -b bugFix
git commit
git checkout master
git commit
git merge bugFix
Copy the code
Rebase makes the code much cleaner. The following illustration illustrates the use of the rebase command.
git checkout -b bugFix
git commit
git checkout main
git commit
git checkout bugFix
git rebase main
Copy the code
2. The HEAD movement
HEAD always points to the last committed record on the current branch. Most Git commands to modify a commit tree start by changing the point of the HEAD.
Can move up and down through the HEAD, very convenient function.
The following figure demonstrates that you can specify the HEAD pointer directly with the hash value. With checkout, you can roam to any submission at any time.
git checkout c4
Copy the code
Through special symbols such as ^ and ~, the relative jump can be completed. You don’t have to look around for a really long hash. Look at the picture and speak.
git checkout bugFix
git checkout HEAD^
Copy the code
Of course, you could just simplify it to
git checkout bugFix^
Copy the code
Isn’t that easy?
Similarly, the symbol ~, which can be followed by a number, is used for successive steps. Let’s see what it does.
git branch -f bugFix HEAD~2
git branch -f main c6
git checkout HEAD^
Copy the code
Both reset and revert use back-and-forth submissions. Relatively speaking, reset is local and revert is remote.
git reset c1
git checkout pushed
git revert c2
Copy the code
The above features cover 90% of git operations. But if you can’t play with the other 10 percent, it can be very troubling in some cases.
3. cherry-pick
If you want to copy some commits below the current location (HEAD), cherry-pick is the most direct way. I personally love cherry-pick because it’s so easy.
Git rebase differs from Git Rebase in that you can just pick and submit parts of it and grab them.
git cherry-pick c3 c4 c7
Copy the code
Alternatively, we can use interactive Rebase. For example, git rebase -i HEAD~n will open a dialog to make adjustments, which won’t be repeated here.
Interactive rebase refers to the use of the rebase command with the argument –interactive, abbreviated -i.
4. A few tips
After learning these above, it can be said that you should be at work with ease. Here are a few commonly used techniques.
To complete the transformation shown above, simply switch to the main branch and executegit cherry-pick c4
Can.
git checkout main
git cherry-pick c4
Copy the code
The following example is a little more troublesome. You did one submission on the newImage branch, and then you created the Caption branch based on it, and then you did another submission. At this point you want to make some minor adjustments to some previous commit record. Let’s say the designer wants to change the resolution of the image in the newImage, even though the submission record is not up to date.
git rebase -i HEAD~2 # change the order of C2 and C3
git commit --amend
git rebase -i HEAD~2 # change the order of C3' and C2
git branch -f master
Copy the code
Git commit — Amend means that the error information of the last commit is overwritten, the last commit information can not be seen on the gITk graphical interface, and the previous information can not be seen in git log, and add and commit means adding a new information.
We can do this in another way. Cherry-pick can be used to append commit records from anywhere in the commit tree to the HEAD.
git checkout main
git cherry-pick newImage
git commit --amend
git cherry-pick caption
Copy the code
Git tags are used to tag records.
git tag v0 c1
git tag v1 c2
git checkout c2
Copy the code
5. Advanced skills
Sometimes, you need to work hard to organize your submission records into a nice order. This is true for some teams that strive for excellence, but not for most teams.
That’s why it’s called advanced technique. For example, for the transformation of the following image, we need to go through multiple rebases.
git rebase main bugFix
git rebase bugFix side
git rebase side another
git branch -f master another
Copy the code
Special symbols such as ~ and ^ can be used to jump quickly, and they are even more attractive when linked together.
git branch bugWork HEAD~^2~
Copy the code
For example, to complete the branch creation above, we only need one command. Git Brach bugWork C2 is also available.
Let’s do a more complicated example.
git checkout one
git cherry-pick c4 c3 c2
git checkout two
git cherry-pick c5 c4 c3 c2
git branch -f three c2
Copy the code
6. Remote warehouse
The clone command is the most basic command to copy a remote repository. To do this, simply execute the Git clone command.
With the following command, you can see the HEAD separation status of the remote and local warehouses.
git commit
git checkout o/master
git commit
Copy the code
The following figure illustrates the fetch directive in action. Git fetch does not change the files on the local disk, it just synchronizes the remote data and moves the pointer on the remote branch. Fetch is just the download action. Take the transformation of the image below.
Git pull is short for Git fetch and Git Merge. The following figure shows this process.
git pull
Copy the code
The following is the answer to the next level, fakeTeamwork is a self-made command in this tutorial.
git clone
git fakeTeamwork 2
git commit
git pull
Copy the code
Git push is also a very simple command, so I won’t cover it.
git commit
git commit
git push
Copy the code
The levels below are getting more and more complex, and the screenshots don’t look good. I’m going to give you the answer, so you can actually do it.
07. Deviated submission history
git clone
git fakeTeamwork 1
git commit
git pull --rebase
git push
Copy the code
08. Lock the master
git reset --hard o/main
git checkout -b feature C2
git push origin feature
Copy the code
End
So, how do I get the address of this tool?
The method is as follows: Follow the public account xjjdog and reply to git to obtain the actual drill address online. At the same time, a complete set of optimal schemes for git learning will be obtained. (Amazing gadgets)
With these tools, you can save a lot of time, you can spare a few seconds, give me a triple.
Welcome to star: github.com/xjjdog/bcma… . It includes ToB complex business, Internet high concurrency business, cache applications; DDD, microservices guidance. Model driven, data driven. Understand the evolution of large-scale services, coding skills, Learning Linux, performance tuning. Docker/ K8S power, monitoring, log collection, middleware learning. Front-end technology, back-end practices, etc. Main technology: SpringBoot+JPA+Mybatis-plus+Antd+Vue3.
Xjjdog is a public account that doesn’t allow programmers to get sidetracked. Focus on infrastructure and Linux. Ten years architecture, ten billion daily flow, and you discuss the world of high concurrency, give you a different taste. My personal wechat xjjdog0, welcome to add friends, further communication.