Git Series 2-Git Quick Start

introduction

The previous article made a simple comparison between SVN and Git. This article will introduce the application of Git and explain it in conjunction with the specific use of the editor in the work. I believe that after reading this article, I can deal with the general use of Git in the work. .


First look at the main content of this article, as shown below:


It is mainly divided into two parts: daily development and basic configuration. Daily development will introduce the basic concepts, commands and processes used in Git. The basic configuration is mainly to say that in order to cope with the situation in the work, we need to ignore some files when submitting, and In order to improve work efficiency, some operations of setting aliases to commands are required.


Download and install

        Here, I only introduce the installation of Git on the Windows platform. For other platforms, please refer to the official website. The Git download address is: https://git-scm.com/download/

        Installing Git under the Windows platform is relatively simple. Find the Windows platform to download the installation file from the above address page, and then it will be no different from installing other applications. After the installation is complete, click the right mouse button in any folder, we will see two new options "Git GUI Here", "Git Bash Here", here it is recommended to use Git in the form of Git Bash, after all, ported from Linux The thing that comes over is to use the command line mode to play its main role, to appreciate the real operation behind the GUI. The following operations will also be based on the Bash mode. Click the corresponding option to open the command line mode window. The general form is shown in the following figure:

        Enter git --version here, you can view the git version to determine that the correct git has been installed.


Daily development

        After the download is complete and the installation is complete, we need to configure the name and email to distinguish the user information submitted. The command is as follows:

$ git config --global user.name "Your Name"
$ git config --global user.email "your [email protected]"

        Before starting the development work, we will get a remote git warehouse address xxx, we can use the git clone xxx command to clone the remote warehouse to the local warehouse. At this moment, our local warehouse has exactly the same version repository as the remote warehouse. We can use the git log command to view the team's commit record and clearly know the specific content of each commit.

        On the other hand, if it is a new project, or to practice using git, how do we need to create a new git repository and change it? Enter your working directory and run the git init command under git bash to initialize a git repository.

        Well, with the local version library, we can develop happily locally. . .

        After some time, when we have developed a function and intend to submit it, the process that needs to be taken is as follows:

        git introduced the concept of staging area, use the "git add." command to add all the changes made in the work area to the staging area, and then submit the contents of the staging area to the git commit -m "modification instructions" We can add changes to the staging area by executing the git add command multiple times, and submit the changes to the current branch with only one git commit command.

        The local library has been modified. If it is teamwork, we need to synchronize our changes to the remote library. At this time, we must use the git push command: git push remote library name remote library branch.

        Throughout the process, we can use the git status command to view the status of files modified by the local repository.


basic configuration


Ignore special files

        In the usual development, we do not want to submit some generated files to the git repository, such as the .class files generated by java compilation. At this time, we need to set the special files to be ignored when git is submitted. "File, and submit to git, the file content format is as follows:

.DS_Store
.idea/
.metadata
*.iml
*.class
*.jar
.DS_Store
proto/gen-*
logs
**/target/*
target

#eclipse and myeclipse
.settings
.classpath
.project
.myeclipse
.mymetadata

## File-based project format
*.ipr
*.iml
*.iws
*/src/main/resources/dubbo.properties
**/caches/*.cache*
        Friends who use windows have noticed that when the .ignore file is directly in the folder, the operating system will report the following error:


        At this time, we can use the save or save as function of the text editor to create this file. Let me say one more thing: It is recommended to use Notepad ++, the function is still relatively powerful, and it is also very convenient.


Alias ​​settings

        Every time we submit our changes to git, we continue to execute commands. After entering for a long time, we will find that these commands are always so few, some commands are very long, and it will take some time to enter. Is there any way to improve efficiency?

        git provides an alias mechanism, we can set a short alias for the executed git command, so that we can achieve the purpose of improving the speed of input

$ git config --global alias.st status
$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.br branch

        Through the above few simple commands, we can achieve the effect of setting the alias, so that after the execution of git st, git co, git ci, git br, they represent the corresponding view changes, switch branches, submit code, View common functions of branches.

to sum up

        Well, through the introduction of this article, I believe that you are no longer familiar with the use of Git. In addition, as I learn by myself, there are still some questions or problems that need to be solved:

        1. Compared with SVN, why does Git have a concept of a cache area;

        2. There are many parameters for the commands that are usually applied, some of which are also very important, need to be sorted out and clarified;

        3. For commonly used commands, you need to set the corresponding alias to improve your work efficiency.

        In fact, there is a certain difference between the content currently introduced and the actual use in the work. The main difference is the management of the branch. This will be introduced in the following blog post.


References

        recommend! Teach you how to use Git  -if you are a novice, it is strongly recommended to implement all the examples in this article

        Git tutorial, Liao Xuefeng's official website -It is said to be the most easy-to-understand Git tutorial in history, after reading it, I feel really good

        githug   -Learn Git in the game of level crossing (need to configure the Ruby environment, personally test the Kaner in the second level under Windows, can't survive ...) (Bonus: customs clearance guide )

Published 159 original articles · praised 225 · 210,000 views

Guess you like

Origin blog.csdn.net/lyg673770712/article/details/50120957