Learn Git (c) create Git repository

Git repositories

What is it Git repository, also known as warehouse repository, we can understand him as a folder. This folder of all the things that need to be modified to manage Git, the antithesis of each file, edit, delete Git will be recorded in order to trace the history of a certain time or any time can "restore" in the future.

There are two ways to create a Git repository

  1. Import all the files in the current directory or to Git project in
  2. Cloning an existing Git repository server from a

We are in daily use development to create the second.

Initialization warehouse in an existing directory

We first need to create a new empty directory in a place such as the D drive in a new directory gitTest
Here Insert Picture Description
open Git git init command console through this directory can become a Git repository management in this directory

$ git init
Initialized empty Git repository in D:/gitTest/.git/

After completion of the run command to create a subdirectory named .git, this subdirectory containing your initialization Git repository of all files must be used to track and manage Git repository, all right, do not manually modify the file or folder , or change the mess, and put Git repository to destroy. If you do not see the need to set up hidden folders to be visible, so you can see it.
However, at this time, we just made an initial operation of your project files have not been tracked.

Cloning an existing warehouse

If you want to get a copy of the Git repository already exists, for example, you want to pull the rest of the company or project, then we should use git clone command.

$ git clone https://github.com/libgit2/libgit2

This creates a directory in the current directory named "libgit2" and initializes a .git folder in this directory, from a remote repository pull to remove all your data into .git folder and read from the latest version of a copy of the file. If you enter into this new libgit2 folder, you will find all the project files already there, ready to wait for subsequent development and use.

Submission of documents to the repository

Now we need to create the corresponding repository directory in a file, such as readme.md scheduled to be put under gitTest (your new warehouse) directory (subdirectories too), because this is a Git repository, and then put the rest of Git powerful can not find the file.
Here Insert Picture Description
Submission of documents to the repository requires two steps
1. git add command tells Git, to add files to the repository

$ git add readme.md

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

2. Use the git commit command tells Git, the submission of documents to the repository

$ git commit -m "提交 readme"
[master (root-commit) 1f26829] 提交 readme

 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 readme.md

Explain git commit command, type -m behind this explanation is submitted, 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. After just found the back with a git command - shorthand note is that message mode -mm mean, if found the back with two --xxxx that is sure to write a complete word.

git commit command is successful will tell you, 1 file changed: 1 file has been changed (our newly added readme.md file);

Why Git add files need to add, commit a total of two steps it? Because commit can submit many files at once, so you can add multiple different files such as

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

Guess you like

Origin blog.csdn.net/qq_16830879/article/details/89711545