Git--Create a repository

Source: Internet
Author: User
Tags version control system

What is a repository?

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.

Therefore, it is very easy to create a repository

First , select a suitable place to create an empty directory:

$ mkdir learngit$ cd learngit$ pwd/users/michael/learngit

pwdThe command is used to display the current directory. On my Mac, this warehouse is located /Users/michael/learngit .

If you are using a Windows system, in order to avoid any puzzling problems, make sure that the directory name (including the parent directory) does not contain Chinese.

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

 in/users/michael/learngit/.git/

Instantly Git has built the warehouse, and tell you is an empty warehouse (empty Git repository), careful readers can find the current directory is a directory of more than one, .git this directory is git to track the management of the repository, it's OK don't manually modify the directory inside the file , or change the mess, the Git repository to destroy.

If you don't see the .git directory, it's because the directory is hidden by default and ls -ah can be seen with commands.

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. However, it is not recommended that you use the company project you are developing to learn git, otherwise you will not be responsible for any consequences.

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 every change, such as adding a word "Linux" to line 5th, and deleting a word "Windows" on line 8th. 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 not able to track changes in Word files, the previous example is just to demonstrate that if you want to really use version control system, it is necessary to write the file in plain text.

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

Children's shoes using Windows should pay special attention to:

Never edit any text file with a Notepad that comes with Windows. The reason is that Microsoft Development Notepad team used a very mentally retarded behavior to save UTF-8 encoded files, they are smart to add 0XEFBBBF (hex) characters at the beginning of each file, you will encounter a lot of incredible problems, for example, the first line of the page may show a "?", obviously the correct procedure to compile a report on grammatical errors, and so on, are caused by the mentally retarded behavior of Notepad. Suggest you download notepad++ instead of Notepad, not only powerful, but also free! Remember to set the default encoding for notepad++ to UTF-8 without BOM:

Now, let's write a readme.txt file that reads:

is are free software. 

Be sure to put learngit it in the directory (subdirectory is also OK), because this is a git repository, put it elsewhere git can not find this file.

It takes 3 steps to put an elephant in the freezer, and it takes only two steps to put a file into a git repository.

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 Unix philosophy is "No news is good news", stating add success.

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

" wrote a readme file " [Master (Root-12 insertions (+100644 Readme.txt

simply explain: git commit command, -m followed by the description of this submission, you can enter any content, of course, it is of great significance, so that you can easily find changes in the history record.

Too much trouble not to enter the -m "xxx" line? There are ways to do this, but it's strongly not recommended, because it's important for you to read to others. I do not want to enter the description of children's shoes please google, I do not tell you this parameter.

git commitWhen the command executes successfully, it will tell you that 1 files have been changed (our newly added Readme.txt file), inserting two lines of content (Readme.txt has two lines of content).

Why does git need to add files add in commit two steps? Because commit you can submit many files at once, you can have add different files several times, such as:

" add 3 files. "

Summary

Now summarize the two things you learned today:

1. Initialize a git repository and use the git init command.

2. Add files to the Git repository in two steps:

    • The first step, use the command git add <file> , note, can be used repeatedly, add multiple files;

    • The second step, using git commit the command, is done.

 

Git--Create a repository

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.