preface
We know that a commit object is a version, so we have a historical breakthrough in a version, so we need to record it. In Git, you can use tags to record it. When we work we need partners which means we need to collaborate remotely! Here are their functions and some easy to use.
A, the Tag
Git can use tagging, or tagging, a commit object. Similar to the version of the game ~
-
Listing tag command: git tag
-
Create tag Lightweight tag: This tag functions like a branch, except that the tag cannot be moved.
Git tag v1.0 [commitHash]
Note tag: This tag is a complete object stored in the Git database. They are tested; The tag will contain the name, email address, and date and time of the person who made the tag; We usually create a note label, but if you don’t want to save information for some reason then you can opt for a light label.
Git tag -a v1.1
Git tag -a v1.1 commitHash
Git tag -a v1.1 commitHash -m “version v1.1”
View tag: This tag functions like a branch, except that the tag cannot be moved.
Command: git show tagname
Delete tag: This tag functions like a branch, except that the tag cannot be moved.
Command: git tag -d tagname
Check out tag: This tag functions like a branch, except that the tag cannot be moved.
Git checkout tagname
That wraps up some basic operations, and the next step is to talk about teamwork in conjunction with GitHub.
2. Remote warehouse
To be able to use team collaboration on Git projects, we need to know how to manage our own remote repository. The content of the remote repository is the repository of my project. Generally speaking, we can have many remote repositories. Working with others on common tasks requires mastery of managing remote warehouses and pushing or pulling data as needed. Let’s get started on the remote repository. First we need to open the GitHub website, register and create a new repository.
1. Create a remote repository
2. Configure a simple name for the remote repository
-
Git remote add name URL
-
What it does: Add a new remote Git repository and specify a shorthand we can easily remember.
-
Command: git remote -v
-
Display Git aliases used by remote repositories and their corresponding URLS.
-
Git remote rename pb Paul
-
Function: Renames.
-
Command: git remote rm name
-
Function: Remove remote warehouse.
3. Push the local project to the remote repository
- Git push remote-name branch-name command
- Function: Pushes the commit object to the remote repository. (Remote trace branch will be generated when push, which will be explained in more detail later)
4. Klon Remote warehouse
- Git clone URL
- Function: Clone remote warehouse.
5. Invite members to join the project
When we sign up for GitHub, we have an email address to fill in, and the invitees will receive an email to open and follow instructions to become members of the project.
6. The project leader updates the content submitted by the members
- Git fetch [remote-name]
- Function: Clone remote warehouse.
This command accesses the remote repository and retrieves data that is not yet available in the local repository. Note that this command does not automatically merge or modify the data to the current work, we need to do the receive merge.
Three, remote tracking branch
A remote trace branch is a reference to the state of the remote branch. They are local branches that you can’t move, they move automatically when you do any network traffic. When a repository is cloned, a master local branch is automatically generated and the corresponding remote trace branch has been traced. When you create a branch, you can specify which branch to track by running the following commands :1. Git checkout -b branch name 2.
The git push command is very long and requires the remote branch name and the local branch name, which is too troublesome. We need to optimize it. If you can bind the local branch to the remote branch then you can use git push directly.
Git branch -u = git branch push = git branch push = git branch push = git branch push
4. Conflict resolution
If we write code in the local repository, there will be conflicts, so we will store our code in the remote repository and work with colleagues to complete the project, so there will also be conflicts. We will use Git push(push code to the remote repository) and git pull(get code from the remote repository), which will produce conflicts. So let’s look at how conflicts arise and how they can be resolved.
- Conflicts caused by Git push
If two people move a file in the same place, then git push will cause conflict. It can be better understood by the following diagram.
- Git pull conflicts
If a file in the remote library has content on line 6, and your local code happens to be on line 6, and you want to do git pull, then you’re going to have a conflict. We don’t want to pull because it’s not committed locally, but that’s a possibility. (If this sounds familiar, it’s the same)
Five, the end
So far, Git is finished, just record the learning process, if there are mistakes, please point out, thank the audience master graces. To get a PDF version of the above, go to GitHub.
Address: Git Study notes area