How to quickly create a version Library
What is a version library? A version library, also known as a repository, has the English name repository. You can simply think of it as a directory. All files in this directory can be managed by Git, and each file can be modified or deleted, and Git can be tracked, so that you can track history at any time, or "Restore" at a certain time point in the future ".
Therefore, it is very easy to create a version library. First, select an appropriate place to create an empty directory:
$ mkdir learngit$ cd learngit$ pwd/Users/michael/learngit
The pwd command is used to display the current directory. On my Mac, this repository is located/Users/michael/learngit。
If you are using a Windows system, make sure that the directory name (including the parent directory) does not contain Chinese characters to avoid various inexplicable problems.
Step 2: run the git init command to change the directory to a Git-managed Repository:
$ git initInitialized empty Git repository in /Users/michael/learngit/.git/
Git builds the repository in an instant and tells you that it is an empty repository (empty Git repository). careful readers can find that there is another repository in the current directory.The. git Directory, which is used by Git to track and manage version libraries. Do not manually modify the files in this directory. Otherwise, the Git repository will be damaged.
If you do not seeThe. git Directory, which is hidden by default.The ls-ah command is displayed.
You may not have to create a Git repository in an empty directory. You can also select a directory that already has something. However, it is not recommended that you use a company project you are developing to learn about Git. Otherwise, you will not be liable for any consequences.
Add files to the version Library
First, let's clarify that all version control systems can only track changes to text files, such as TXT files, web pages, and all program code. Git is no exception. The version control system can tell you every change. For example, if you add the word "Linux" in line 5th and delete the word "Windows" in line 8th ". Although binary files such as images and videos can also be managed by the version control system, they cannot track file changes. They can only be chained to each change, that is to say, I only know that the image is changed from kb to kb, but what I actually did? The version control system does not know or can't know.
Unfortunately, Microsoft's Word format is binary. Therefore, the version control system cannot track changes to Word files. The previous example is just for demonstration, to use the version control system, you must write files in plain text.
Because the text is encoded, such as Chinese has commonly used GBK encoding, Japanese has Shift_JIS encoding, if there is no historical issues left over, it is strongly recommended to use standard UTF-8 encoding, all languages use the same encoding, which is not conflicted and supported by all platforms.
Note:
Do not use the notepad that comes with Windows to edit any text files. The reason is that Microsoft development Notepad's team used a very mentally retarded behavior to save UTF-8-encoded files, And They cleverly added 0 xefbbbf (hexadecimal) characters at the beginning of each file, you may encounter many incredible problems. For example, the first line of a webpage may display a "? ", When a program is compiled correctly, a syntax error is reported, and so on, it is caused by the Mental Retardation of notepad. We recommend that you download Notepad ++ to replace Notepad. It is not only powerful, but also free! Remember to set the default code of Notepad ++ to UTF-8 without BOM:
Now we compile a readme.txt file with the following content:
Git is a version control system.Git is free software.
Must be put inIn the learngit directory (sub-directories can also be used), because this is a Git repository and it cannot be found in other places.
It takes only two steps to put a file in the Git repository than to put the elephant in the refrigerator.
Step 1: use commandsGit add tells Git to add the file to the repository:
$ git add readme.txt
If the preceding command is not displayed, the Unix philosophy is "no message is good news", indicating that the addition is successful.
Step 2: Use the commandGit commit tells Git to submit the file to the repository:
$ git commit -m "wrote a readme file"[master (root-commit) cb926e7] wrote a readme file 1 file changed, 2 insertions(+) create mode 100644 readme.txt
A brief explanationGit commit command,-M is followed by the description of this submission. You can enter any content. Of course, it is best to make sense, so that you can easily find the change record from the history.
Too troublesome to enter-Can m "xxx" be used? There is indeed a way to do this, but it is strongly not recommended that you do this, because input instructions are very important for others to read. If you really don't want to enter this parameter, please Google it yourself. I won't tell you this parameter.
Git checkout has two lines ).
Why does Git need to add files?Add,What about two steps in commit? BecauseCommit can submit many files at a time, so you canAdd different files, such:
$ git add file1.txt$ git add file2.txt file3.txt$ git commit -m "add 3 files."
Summary
Now, let's summarize the two points learned today:
Initialize a Git repository and useGit init command.
Add the file to the Git repository in two steps:
Step 1: Use the commandGit add Note: You can use it multiple times to add multiple files;
Step 2: Use the commandGit commit, complete.