Git study notes - The Basics

1, viewing the current state

git status

View the current state of the repository. The main system or a file is being modified, but no documents submitted. If you want to view the contents of specific changes, use:

git diff

2, to see history

History detailed version information:

git log

History minimalist version information:

git log --pretty=online

Simple version information such as:

c*19342e35***********e208e8454b0f080ee Merge pull request #8 in PAYP/payresource from paythrift to master

b * 4d754678 *********** bcde53 the size of the new generation

5 * d1597e8e3 ************* 2a13ea596 new generation of memory size optimization

7 * 37e44e ********* 5d641f406ad90745dba optimized filter Save Log

Which commit ID (version number): It is not incremental number, but one is a very large number of hexadecimal SHA1 digital design.

3, version rollback

HEAD is the current version

HEAD ^ is the last version

HEAD ^^ is the last version

HEAD ~ 100 is the 100 version

3.1 Instructions: the current version append GPL fall back on a version of the add distributed, use the command: git reset

git reset --hard HEAD^

3.2 If you now regret it, do not want to roll back, think back to the previous version of the original rollback, as long as in the case of the terminal is not closed (you can find the version number commit id), on the following instructions can be executed: 21c32 is my version number ( commit id)

git reset --hard 21c32

Description 1: Git version number need not all be written on, as long as several former version number can, of course, not too little, or else do not know the Git version.

Note 2: Git version rollback speed is very fast, because: there is a HEAD pointer inside Git, and points to the current file, when performing rollback action, as long as the pointer to append GPL can be.

3.2 If you now regret, and can not find the version number (commit id) before the rollback, need the following steps to find the version number before:

git reflog

4, work area and staging area

Description: .git is a hidden repository.

5, modify management

What is modified:

Adding a character, deleting a character, add a file, delete a file, add and delete the part of the content and so on, all operations are all modified.

Git is to modify the tracking and management, rather than the file.

Execute the following instructions:

If the first run git add, and then work to modify the contents of the execution git commit -m "***", then the contents of the modified local file is not uploaded to the repository.

The reason: git add operation will only add to modify the contents of the first stage area, and modify the contents of git commit -m "***" just uploaded the first added to the branch. The second revision of the content of any course go to work.

Two revisions submitted the correct order:

1)~add,~commit,~add,~commit

2)~add,~add,~commit

6, undo changes

Modify 6.1) dropped workspace

git checkout -- readme.txt

Above git checkout - file is - is critical character. If not - will become a branch of the switch.

6.2) discard the modified staging area

git reset HEAD readme.txt     #回到了场景5.1中-想丢弃工作区的修改
git checkout -- readme.txt

git reset HEAD file command, not only fallback version, you can also modify the state of the staging area work area to fall back.

6.3) version rollback

Introduced in front of rollback version of the instruction :( fallback directive provided that: do not submit content to the remote).

git reset --hard HEAD^

7, delete files

git rm readme.txt
git status     #查看删除后的文件

In addition, when you delete the wrong file, you need to restore operation, the following instructions to restore to the latest version

git checkout -- readme.txt

 

Git rm command is used to delete a file. If a file has been submitted to the repository, so you never have to worry about mistakenly deleted, but be careful, you can only restore files to the latest version, you will lose the contents of the most recent commit your changes .

 

Published 327 original articles · won praise 133 · views 630 000 +

Guess you like

Origin blog.csdn.net/qq_30507287/article/details/85042395