git tutorial

git tutorial -- Liao Xuefeng -- https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

1、

Repository=repository=repository
There are a lot of things in Git's repository, the most important of which is the staging area called stage (or index), and the first branch master that Git automatically created for us, and points to A pointer to the master is called HEAD.
The first step is to use git add to add the file, which is actually to add the file modification to the staging area;
the second step is to submit the changes with git commit, which actually submits all the contents of the staging area to the current branch.
Work area, staging area, current branch

mkdir first
cd first
git init will turn the directory into a warehouse, and an empty Git repository
will generate a .git file, which is used by Git to track and manage the repository. Don't change it if you have nothing to do with
ls -ah You can view the hidden ones .git directory

Can only track changes in text files, such as TXT files, web pages, all program code, etc. Git is no exception

Although binary files such as pictures and videos can also be managed by the version control system, they cannot track the changes of the files. They can only string together each change of the binary files, that is, only know that the picture has been changed from 100KB to 120KB. What has been changed, the version control system does not know and has no way of knowing.
The philosophy of Unix is ​​"no news is good news"
put a file into the Git repository
git add readme.txt //Add the readme.txt file to the "staging area",

use "git add <file>..." to update what will be committed

git add . //Add all files to the "staging area"
git commit -m "information" //Submit the "files in the temporary storage area" to the warehouse, atomically commit

git status //Track the current status of the warehouse
git diff readme.txt //Check what
commit was modified in the readme.txt file last time, use the git diff HEAD -- readme.txt command to view the latest version in the workspace and repository the difference:

git log //You can view the history of commits. The command displays the commit log from the latest to the farthest.
You see a large string of similar 3628164...882e1e0 is the commit id (version number)
is a very large calculated by SHA1 The number, expressed in hexadecimal
git reset // roll back the current version "append GPL" to the previous version "add distributed"

$ git reset --hard HEAD^
HEAD is now at ea34578 add distributed //Specify back to a certain version in the future. Sure enough, I, Hu Hansan, came back. The premise is that there is no push to the remote library.

git reset --hard 3628164
HEAD is now at 3628164 append GPL

Git's version rollback is very fast, because Git has a HEAD pointer to the current version internally. When you roll back the version, Git just changes the HEAD from pointing to the append GPL

git reflog //Git provides a command git reflog to record your every command:
and LICENSE has never been added, so its status is Untracked.

git checkout -- readme.txt //Git will tell you that git checkout -- file can discard changes in the workspace: (checkout is actually replacing the version in the workspace with the version in the repository)


$ git checkout -- readme.txt

Use the command git reset HEAD file to undo the changes in the temporary storage area (unstage) and put it back into the workspace:


$ git reset HEAD readme.txt
Unstaged changes after reset:
M readme.txt


Now you have two options, one is to delete the file from the repository, then use the command git rm to delete it, and git commit:

git rm readme.txt
git commit -m "fix"

Another case is that it is deleted by mistake, because there is still one in the repository, so you can easily restore the mistakenly deleted file to the latest version:

$ git checkout -- test.txt. //git checkout actually replaces the version of the workspace with the version in the repository. Whether the workspace is modified or deleted, it can be "one-click restore".

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325118402&siteId=291194637