Learn Git - Create Repository

First, create a new folder in the current directory, and then create an empty directory:

$ mkdir yenight
$ cd yenight
$ pwd
/c/Users/Zhang San/yenight

pwdCommand is used to display the current directory. If you use Windows systems, in order to avoid baffling encounter a variety of problems, make sure that the directory name (including the parent directory) does not contain Chinese.
The second step, through the git initcommand to manage this directory can become a Git repository:

$ git init
Initialized empty Git repository in C:/Users/Zhang San/yenight/.git/

The Git repository built, and to tell you is an empty warehouse (empty Git repository). You will find more than the current directory a .gitdirectory, the directory is to track and manage Git repository, all right, do not manually modify the file or folder, or change the mess, put the Git repository to destroy.
If you do not see the .gitdirectory, it is because this directory is hidden by default, use ls -ahthe command you can see.

To add files to the repository

All version control system, in fact, can only track changes in text files, such as TXT files, web pages, and so all the code, Git is no exception. Version control system can tell you every time changes, such as on line 5 plus the word "Linux", in line 8 to delete the word "Windows". And pictures, videos binaries, although it can be managed by the version control system, but can not track file changes, only the binary string together each change, which is the only known picture from 100KB changed to 120KB, but in the end what changed, version control system does not know, I could not tell.

Unfortunately, Microsoft Word format is a binary format, and therefore, the version control system is unable to track the changes to Word files, in front of our example just to demonstrate, if you want to really use version control system, it is necessary to write in plain text file.

Since the text is coded, such as Chinese have frequently used GBK coding, Japanese have Shift_JIS encoding, if there is no problem left over from history, it is strongly recommended to use standard UTF-8 encoding, all languages ​​use the same encoding, neither the conflict, they were all platform support.

Do not use the built-in Windows Notepad to edit any text file. The reason is that Microsoft Notepad development team used a very mentally behavior to save UTF-8 encoded files, they try to be smart in the beginning of each file added 0xefbbbf (hexadecimal) characters, you will meet many incredible the problem, for example, the first line of the page may show a "?", obviously the correct procedures to compile a report syntax errors, etc., are caused by the mentally retarded behavior of Notepad. I suggest you download Notepad ++ instead of Notepad, not only powerful, it's free! Remember to Notepad ++ default encoding to UTF-8 without BOM can be.

Now we write a readme.txtfile, as follows:

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

Be sure to put yenightthe directory (subdirectories too), because this is a Git repository, Git worse then put the rest can not find the file.

And the elephant into the refrigerator takes three steps compared to a file in the Git repository requires only two steps.

The first step, use the command git addtells Git, to add files to the repository:

$ git add readme.txt

Implementation of the above command, no display, that's right, Unix philosophy is "no news is good news", indicating successfully added.

The second step, use the command git committells Git, the submission of documents to the repository:

$ git commit -m "wrote a readme file"
[master (root-commit) eaadf4e] wrote a readme file
 1 file changed, 2 insertions(+)
 create mode 100644 readme.txt

Briefly explain git commitcommand, -mentered followed by explanation of this submission, you can enter any of the content, of course, the best is meaningful, so you can from the history list easy to find change records.

I could not be bothered enter -m "xxx"okay? Indeed there are ways to do this, but it is strongly recommended that you do not do it, because the input is very important to explain myself to read to others. Shoes really do not want to enter your own description of Google, I do not tell you this parameter.

git commitAfter the successful implementation of the command will tell you 1 file changed: a file is changed (we readme.txt file newly added); : 2 insertionsinsert the two lines (readme.txt have two lines).

Why add files Git needs add, commita total of two steps it? Because commitit can submit many files at once, so you can multiple adddifferent files, such as:

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

summary

To summarize the contents of two learned today:

Initialize a Git repository, use the git initcommand.

Add files to the Git repository, in two steps:

1. command git add <file>, note that can be used repeatedly, to add a plurality of files;
2 using a command git commit -m <message>, is completed.

Learning Resources: Create repository - Liao Xuefeng's official website

Guess you like

Origin www.cnblogs.com/yidajiabei/p/12056194.html