Git Quick Start

Source: Internet
Author: User
Tags commit version control system
first, know git what Git is.

A distributed version control system. What is a centralized version control system.

Repository is centrally stored in the central server, and work, with their own computers, so the first from the central server to obtain the latest version, and then began to work, finished work, and then put their lives to the central server. Central server is like a library, you have to change a book, you must first borrow from the library, and then back home to change, and then put back to the library.

Centralized version control system The biggest problem is the need to network to work, if it is OK in the LAN, the bandwidth is big enough, fast enough, but if the Internet, if you encounter slow, it will suppress people to death.

What is a distributed version control system.

What is the difference between a distributed version control system and a centralized version control system? First of all, the distributed version control system does not have a "central server", everyone's computer is a complete repository, so that when you work, you do not need to network, because the repository is on your own computer. Since everyone has a full repository on their computers, how can multiple people collaborate? For example, you change the file a on your computer, your colleague also changed the file a on his computer, when you two just push their changes to each other, you can see each other's changes.

Compared with centralized version control system, the security of Distributed version control system is much more, because everyone has a complete version of the library, a person's computer is broken, it does not matter, casually from other people to copy one. and centralized version control system of Central server if there is a problem, everyone can not work.

In the actual use of distributed version of the system, in fact, rarely in the computer between the two people to push the revision of the repository, because it is not in a LAN, two computers can not access each other, or perhaps today your colleague is sick, his computer did not boot. distributed version control system usually also has a "central server" of the computer , but the role of this server is only to facilitate "exchange" everyone's changes, without it everyone also work, just exchange changes inconvenient.

Of course,the advantage of git is not simply to not have to be networked , but also its extremely powerful branch management , leaving SVN and so far behind. Second, install git install git on Windows

Msysgit is a Windows version of Git, which is downloaded from the official website and then installed by the default option.

After the installation is complete, git-- git Bash, a command-line window, is found in the Start menu, which indicates that the GIT installation was successful.

After the installation is complete, you will need the final step, and at the command line, enter:

$ git config--global user.name "Your name"
$ git config--global user.email "Your Email"

Because Git is a distributed version control system, every machine must be tell: your name and email address.

Note that the--global parameter of the git config command uses this parameter to indicate that all of your git repositories use this configuration, and you can also specify a different user name and email address for a particular repository. Third, create the version library

Repository, also known as the Warehouse, English name repository, you can easily understand a directory, all the files in this directory can be managed by git, each file modification, deletion, git can track, so that any time can track history, Or you can "restore" at some point in the future. 1. Steps to create a repository

The first step is to select a suitable place to create an empty directory:

$ mkdir Myrepo
$ CD Myrepo
$ pwd
/c/users/roger/myrepo

The second step is to turn this directory into a repository that git can manage by using the GIT init command:

$ git init
Initialized empty Git repository in c:/users/roger/myrepo/.git/

At this point, the warehouse is created and you are prompted that this is an empty warehouse (empty Git repository). Of course, you don't have to create a git repository in an empty directory, and it's also possible to choose a directory that already has something. 2. Add Files to Repository

First of all, it is clear that all version control systems, in fact, can only track changes in text files, such as txt files, Web pages, all the program code and so on, Git is no exception. The version control system can tell you each change, such as the first few lines and additions and deletions. and picture, video these binary files, although can also be managed by version control system, but can't track file changes, only the binary files each change string up, that is, only know the picture changed from 100KB to 120KB, but what changed, version control system do not know, also can not know.

Unfortunately, Microsoft Word format is binary format, so the version control system is unable to track changes to Word files.

Because the text is encoded, such as Chinese has a common GBK encoding, Japanese has SHIFT_JIS encoding, if there is no historical legacy, it is strongly recommended to use the standard UTF-8 encoding , all languages use the same encoding, there is no conflict, and supported by all platforms.

It's also easy to add files to the repository.

First, we write a Readme.txt file that reads as follows:

Git is a version control system.
Git is free software.

Note that the file must be placed in the Myrepo directory (subdirectories are also OK).

Next, put the file in the Git repository. This process takes only two steps.

The first step is to use the command git add to tell git to add the file to the repository:

$ git Add readme.txt

Execute the above command without any display, that's right. The Philosophy of UNIX is "no news is good news." ", the description was added successfully.

In the second step, use the command git commit to tell git to commit the file to the repository:

$ git commit-m "wrote a Readme file"
[Master (Root-commit) DC767DC] wrote a readme file
1 file changed, 2 inserttions (+)
Create mode 100644 readme.txt

The git commit command after-m input is the description of this submission, you can enter any content, it is recommended to fill in meaningful content, convenient for future from the history record to quickly find changes in the record.

When the git commit command succeeds, it tells you that 1 files have been changed (the newly added Readme.txt file) and two lines of content (Readme.txt have two lines of content) are inserted.

Why does git add files need to Add,commit so two steps. Because commit can commit many files at once, you can add different files multiple times. Like what:

$ git Add file1.txt
$ git Add file2.txt
$ git Add file3.txt
$ git commit-m "Add 3 files."

Detailed tutorial Please poke here: Git tutorial-Liaoche's official website

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.