Foreplay
What is the repository of it? Repository also known as warehouse, the English name repository, you can be understood as a directory, all files in this directory can be inside Git to manage, modify each file, delete, Git can track order history can be traced at any time or you can "restore" at some point in the future.
So, create a repository is very simple, first of all, choose a suitable place, create an empty directory, I built called git_demo
Generates the repository
Into git_demo directory
git init
Initialization (git init) git let us help manage the current folder
# $ git init Initialized empty Git repository in E:/git_test1/git_demo/.git/
Put the Git repository built, and to tell you is an empty warehouse (empty Git repository), you can find more than a .git directory of the current directory, 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 .git directory, it is because this directory is hidden by default, use ls -ah command you can see.
git status
git status detection status of files in the current directory
We created two files api_locust.py and manage.py inside, which just write about content, execute git status command
We can see two new file name is red
Red represents the new files or modify the document before
Green represents git has managed up
git add
Above our file has not been managed git up, git add can be used to manage
# git add manage.py
Such a file manager just manage it, you can use git status View
If you want to manage all the files under the current directory up and use. (Dot)
# git status .
Open manage.py file, just change it in to check the status of
# $ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: manage.py Untracked files: (use "git add <file>..." to include in what will be committed) api_locust.py no changes added to commit (use "git add" and/or "git commit -a")
git told we had a file is modified, a document not submitted
git commit
Git commit command tells Git, the submission of documents to the repository
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.
# $ git commit -m 'v1' [master (root-commit) 0940348] v1 1 file changed, 15 insertions(+) create mode 100644 manage.py
git commit command is executed successfully will tell you, 1 file changed: 1 file has been changed (our newly added manage.py file); 15 insertions: 15 lines inserted content (15 manage.py line content).
git log
View version git log record
# $ git log commit 09403486af1fd13ca9f844326e1bd7c187611be8 (HEAD -> master) Author: zouzou <[email protected]> Date: Mon Oct 14 21:55:46 2019 +0800 v1
Content behind a long list of what we commit the version number, the following is the author and date, vl is added when describing commit us.
Filtering and logging of:
git log --pretty=oneline
#$ git log --pretty=oneline 7eb789f8b7002c432c958c281c838b3076a779a1 (HEAD -> master) v2版本 09403486af1fd13ca9f844326e1bd7c187611be8 v1
to sum up
Initialize a Git repository, use git init command.
View the status, use the command git status
Add files to the Git repository, in two steps:
- Using the command git add <file>, attention, can be used repeatedly, to add a plurality of files;
- Use the command git commit -m <message>, complete