Git is an open source distributed version control system for agile and efficient handling of any project, small or large; Is an open source version control software developed by Linus Torvalds to help manage Linux kernel development; Git is different from the common version control tools such as CVS and Subversion. It adopts the way of distributed version library without the support of server-side software.

 

So, creating a repository is very simple. First, choose a suitable place and create an empty directory:

 $ mkdir learngit  $ cd learngit  $ pwd
Copy the code

The ** PWD ** command is used to display the current directory. On my Mac, the repository is located at /Users/ Michael/Learngit.

If you are using Windows, make sure that directory names (including parent directories) do not contain Chinese characters to avoid confusing problems.

**git init** change the directory into a git managed repository:

 $ git init
Initialized empty Git repository in /Users/michael/learngit/.git/
Copy the code

Git repository: Git repository: Git repository: Git repository: Git repository: Git repository: Git repository: Git Repository Git repository is destroyed.

If you don’t see the **.git directory, that’s because it’s hidden by default and can be seen with the ls -ah** command.

Now we’ll write a readme.txt file that looks like this:

Git is a version control system.
Git is free software.
Copy the code

Be sure to put it in the Learngit directory (or subdirectory), because this is a Git repository and you won’t find it anywhere else.

Putting a file in a Git repository takes two steps, compared to three steps to putting an elephant in the fridge.

First, tell Git to add the file to the repository with the **git add** command:

 $ git add readme.txt 
Copy the code

Execute the above command, nothing is displayed, that’s right, the Unix philosophy is “no news is good news”, indicating success.

Git commit:

 $ git commit -m  "wrote a readme file" 
Copy the code

Git commit: -m** git commit: -m** git commit:

**-m “XXX “** There are ways to do this, but it is strongly discouraged because the input instructions are important to yourself and to others to read. If you really do not want to enter the instructions please Google, I will not tell you this parameter.

**git commit** will tell you that one file has been changed (our new readme.txt file) and two lines have been inserted (readme.txt has two lines).

Git adds files with **add and commit. Because commit** can commit many files at once, you can add different files multiple times, such as:

$ git add file1.txt
$ git add file2.txt file3.txt
$ git commit -m "add 3 files."
Copy the code
Git status: readme.txt has been modified, but is not ready to commit.Copy the code

Although Git tells us that readme.txt has been modified, it would be nice to see exactly what has been changed. **git diff** git diff** git diff**

$ git diff readme.txt 
Copy the code
Git diff = difference = difference = difference = difference = difference = difference = difference = difference = difference = differenceCopy the code

Git add** git add** git add** git add** git add** git add**

 $ git add readme.txt 
Copy the code

Again, no output. Before the second step **git commit, run git status** to check the current repository status:

 $ git status
Copy the code
In practice, it's impossible to remember in your head what a document with thousands of lines has changed every time, otherwise you wouldn't need a version control system. The version control system must have some command to tell us the history. In Git, we use Git log to check:Copy the code

The git log command displays the most recent to the most distant commits. We can see three commits, the most recent is append GPL, the last is ** Add Distributed, and the first one is “Wrote a readme file”. Pretty =oneline**

 $ git log --pretty=oneline
Copy the code
 
Copy the code

General tutorials have, the following summary of their own problems:

$ git add tt.txt

fatal: pathspec ‘tt.txt’ did not match any files

In fact, it is very easy to solve, is to create a new tt.txt file, and then put in the directory can be. Git add tt.txt

Of course, you can write something before you add it, and then add it again. Don’t use Notepad, use another text editor. Notepad++ would be appropriate.