preface
Git is a tool so integral to our work today that it has spawned many visualization tools (sourceTree…). To help us operate local and remote code repositories more easily. However, this approach is a bit stiff, and typing git commands on your own makes you feel more in control. In addition to the usual operations, this article documents a few commands that aren’t used much at first.
The label
In my daily development, I will tag each version that goes online. This can not only be used to distinguish the version that goes online each time, but also can be rolled back at any time.
git tag
$git tag -a v1.0 -m "version 1.0" $git push origin v1.0 Note that this cannot be repeated.Copy the code
Yes, it’s easy. Just add it when you go live. We can execute git tag directly when checking the historical version. To roll back code:
$git checkout v1.0Copy the code
merge
There must be only one main branch of our code repository, and those people working together will involve merging their own code into the main branch. So there are two operations involved heregit rebase
与 git merge
.
git rebase
$ git:(master) git rebase develop
Copy the code
Git rebase. So is his merger strategy. Git /rebase: git/rebase: git/rebase: git/rebase: git/rebase: git/rebase , think about it. Git rebase will also be used during development to manipulate the current commit and merge multiple commits into one. This will make the commit record clear and easy to read and manage.
git merge
$ git:(master) git merge develop
Copy the code
Git merge git merge So is his merger strategy. For example, if we want to merge code submitted by other colleagues on the Master branch into our own branch, we will simply merge the two. Git rebase is the main branch of the git merge. Git rebase is the main branch of the git merge. Here’s a picture to illustrate:
You can see the relationship between the two directly from the picture. If you encounter code conflicts, usegit rebase
It can also be executed after the conflict is resolvedcontinue
Continue merging.
The rollback
You have to roll back your code when you submit it remotely and suddenly you have a problem, you have a problem getting your project online, and so forth.
git reset
git reset [--hard | --mixed | --soft] [<commit>]
Copy the code
— Hard changes the HEAD reference to the repository, the contents of the cache/workspace, and the HEAD reference to the commit version. The cache/workspace contents are replaced
— Mixed with this parameter, the workspace code is not refreshed, the HEAD reference is changed, and the cache content is updated
Soft only changes the direction of the HEAD reference
git checkout
Checkout is generally used to switch branches and roll back code.
git checkout branchName
Copy the code
When checkout rolls back, it changes the direction of the HEAD reference. Note that the contents of the workspace are updated.
It looks like this:
conclusion
The Git instructions mentioned in this article are relevant to your work, and you may encounter some problems when you start using them. But do it more often, and you’ll get it. After all, Git is relatively slow to update in terms of other technologies.
Come on.