The preface took some time to learn about the GIT version management tool. After using SVN, git is actually better and more powerful than SVN. I briefly summarized some git usage commands. If you want to understand git, please slam the recommendation learning website below.
Use Summary to create a version Library: initialize a git repository and use the GIT int command
Add the file to the GIT repository in two steps:
View content
You can use the git status Command to understand the status of the workspace at any time.
If git status tells you that a file has been modified, you can use git diff to view the modification content.
Version rollback
The version pointed to by head is the current version. Therefore, git allows us to move between version history and use commandsGit reset -- hard commit_id.
Before shuttle, useGit logYou can view the submission history to determine which version to roll back.
To return to the future, useGit reflogView the command history to determine which version to return.
Undo Modification
- Scenario 1: When you disrupt the content of a file in the workspace and want to discard the modification, run the following command:Git checkout -- File.
- Scenario 2: When you not only disrupt the content of a file in the workspace, but also add the file to the temporary storage area, you want to discard the modification in two steps. The first step is to use the commandGit reset head FileAnd then return to scenario 1. Step 2: perform operations according to scenario 1.
- Scenario 3: If you have submitted an inappropriate modification to the version library, you want to cancel this submission and roll back the version, provided that it is not pushed to the remote database.
Delete an object
- Run git RM to delete a file. If a file has been submitted to the version library, you never have to worry about accidental deletion. But be careful that you can only restore the file to the latest version, you will lose the content you modified after the last submission.
Add remote database
- To associate a remote database, run the following command:Git remote add origin [email protected]: path/repo-name.git;
- After Association, use the commandGit push-u origin masterPush all the content of the master branch for the first time;
- After that, you can use the commandGit push origin masterPush latest changes;
- One of the biggest advantages of a distributed version system is that you do not need to consider the existence of a remote database when working locally, that is, whether the remote database works normally or not, SVN refuses to work when there is no Internet connection! When there is a network, it is very convenient to push the local commit and synchronize it!
Clone from remote database:
- To clone a repository, you must first know the repository address and then useGit cloneCommand Clone.
- Git supports multiple protocols, including https, but the native git protocol supported by SSH is the fastest.
Create a merge Branch:
- Git encourages extensive use of branches:
- View branch: git Branch
- Create branch: git BranchName
- Switch branch: git checkoutName
- Create + switch branch: git checkout-BName
- Merge a branch to the current branch: git mergeName
- Delete branch: git branch-dName
Resolve conflicts:
- When git cannot automatically merge branches, the conflict must be resolved first. After resolving the conflict, submit it again and merge it.
- UseGit log -- GraphCommand to view the branch merge chart.
Branch Management Policy:
- Git branch is very powerful and should be fully applied in team development.
- Add-- No-FFThe parameters can be merged in the normal mode. The merged history has branches. It can be seen that the merging has been performed, andFast forwardMerging cannot be seen in the past.
Bug Branch:
- When fixing a bug, we will fix it by creating a new bug branch, merging it, and deleting it;
- When the work is not completedGit stashAnd fix the bug.Git stash pop, Return to the work site.
Feature Branch:
- Develop a new feature. It is best to create a new branch;
- If you want to discard a branch that has not been merged, you can useGit branch-D nameForce Delete.
Multi-person collaboration:
View the remote database information and useGit remote-V;
If a new local branch is not pushed to a remote server, it is invisible to others;
Push the branch from the local device, and useGit push origin branch-nameIf the push fails, useGit pullCaptures remote new submissions;
Create a local branch corresponding to the remote branch and useGit checkout-B branch-name origin/branch-name, The name of the local branch should be the same as that of the remote branch;
Create an association between a local branch and a remote branch.Git Branch -- Set-upstream branch-name origin/branch-name;
Capture a branch from a remote device and useGit pullIf a conflict exists, you must first handle the conflict.
Tag management:
CommandGit Tag NameCreates a new tag. The default value is head. You can also specify a commit ID;
-A tagname-M "blablabla..." can specify tag information;
-S tagname-M "blablabla..." you can use the PGP signature label;
CommandGit tagYou can view all tags;
Operation label:
CommandGit push origin tagnameA local tag can be pushed;
CommandGit push Origin -- tagsYou can push all unpushed local labels;
CommandGit tag-D tagnameYou can delete a local tag;
CommandGit push origin: refs/tags/tagnameYou can delete a remote tag.
GitHub:
On GitHub, any fork open-source repository can be used;
You have the read and write permissions of the warehouse after fork;
You can push the pull request to the official repository to contribute code.
Ignore special files:
- When you ignore some files, you need to write. Gitignore.
- . GitignoreThe file itself needs to be placed in the version library, and you can. GitignoreVersion Management!
Configuration alias:
- Similar to: $ git config -- Global alias. St status
- If you configure an alias for git, You Can Be lazy when entering commands.
To build a git server: Refer to setting up a git Server
Add a git cheat sheet:
Recommended git tutorials for relevant learning Websites
Git Official Website
Distributed version control system-Git usage