I first learned about Git through exposure to the well-known open source community Github, but never learned it systematically. This time, I am determined to learn it systematically from beginning to end, and I will also record the learning process here for your criticism. This post starts with a brief look at Git in the following ways.
An introduction to Git and how Git relates to GitHub
Git download and initialization information configuration
Git's basic commands and what they mean
I. Introduction to Git and the relationship between Git and GitHub
First of all, Git was created by Linus Torvalds, the creator of Linux. When the great man opened Linux in the spirit of open source, it was necessary to manage the code of thousands of contributors, initially all the code was sent to Linus by email, and then he would integrate it manually. But as Linux gets bigger and bigger, the amount of code gets bigger and bigger, and it can no longer be managed entirely by people. Linus then chose to manage the code using a commercial system, BitKeeper, a full-fledged version control system, until the two partnerships ended in 2005. So the Linus gods spent two weeks writing out a version control system in C, the now unbeatable Git. (That's what cows look like! ), want to learn more about the history of Git, you can check the information yourself, here is a brief interception of part of the time to stimulate interest in git.
A version control system is a type of system used to manage our project progress points, giving a record of each change and allowing for immediate rollback in case of errors. Think about the changes we usually make to files, once the changes are made, the previous content will be lost, that is, you want to go back to some unmodified state in the past, it is impossible to do so. And we use a version control system to track our project files, and every change is recorded and can go back at any time. Here we won't discuss the difference between centralized and distributed version control systems, we'll just tell you about Git's distributed nature, and you'll understand the various advantages of distributed when you're done learning.
We are probably more familiar with GitHub than Git. It is an open source community and a platform. Many great projects are open sourced on it for programmers around the world to learn and refine. For example: apache/tomcat, eclipse/jetty, jquery/jquery, etc. We say that Git can record every change we make to our work files so that we can quickly restore them, but in order for multiple people to work together, we need to share the same project source code, so we usually put the project source code on a server, and each developer downloads the latest project from the server and works on it, and pushes the changes they made to the server after they finish working on it, so that everyone is developing (modifying) every feature of the project all the time, and of course the project located on the server will record every commit change made by everyone all the time. (The culprit can be found quickly if something goes wrong). And with GitHub as an open source community platform, it can act as that server. However, since it is open source, it is also generally not recommended to use GitHub as a public server for internal company projects. You will usually build your own server configured as a Git server and use it in the intranet.
2、 Git download and initialization information configuration
Of the three platforms, I'll introduce Git installation from the windows platform that I use myself, as for the installation on Linux and MacOS you can check the information yourself. Installation of Git on the windows platform is simple, just go to https://git-for-windows.github.io downloadingmsysgit and install it with a single click. msysgit is integrated with Git and Cygwin, Cygwin is a tool to simulate Linux/Unix environment in windows, because Git is required to use some tools of Linux/Unix, so someone integrated both to make it possible to use Git in windows platform. Here we briefly talk about the configuration of the initialization information for Git.
First after the installation is complete， The right mouse button will add theGit Bash here options， that isGit The command line mode of the， We click to display the command line window。 The first thing we have to do is tellGit， Identity of this machine。 Because later on, when we're working with multiple people， each timeGit The current submitter will be signed at the time of submission， but (not)Git How the information about the submitter was learned？ That's what we tell it when we initialize the message。
Generally we can configure the above two information, as for other information configuration, such as: the default editor, etc., you need to use when you can check the information simply configure it. At this point, a brief introduction to Git is basically complete, so let's look at a few of the longest used Git commands and their meanings in everyday projects.
III. Basic Git commands
This subsection is the core of this post and deals with initializing the repository, adding trace files, staging files, committing to the local database, restoring to a previous state, etc. These basically cover the most common operations in everyday projects, but they are not enough to get a more flexible grasp of Git to make the most of its great role in project management. Here we look at the first command, initialize the repository.
This is a command used to initialize the repository. Executing it will create a .git folder in the current directory, which is used to manage changes to all files in the current directory. For example, I create a folder single in the F drive of my computer, cd to that directory in the git command line, and then execute git init , which results in the following.