Introduction to Git commands

1.Minimum placement

User information needs to be configured before using Git, including user.name and user.email

git config --global user.name 'your_name'
git config --global user.email '[email protected]'(最好确保此地址可用)
说明:
git config --local,local只对某个仓库有效
git config --global,global对当前用户所有仓库有效
git config --system,system对系统所有登录的用户有效
显示config的配置,加list
git config --list --local
git config --list --global
git config --list --system

2. Create the first warehouse and configure local user information

Two scenarios

1.把已有的项目代码纳入Git管理
    cd  项目代码所在的文件夹
    git init
2.新建的项目直接用Git管理
    cd 某个文件夹
    git init your_project #会在当前路径下创建和项目同名的文件夹
    cd your_project

Insert picture description here

小结:
git init 仓库名,创建仓库
global 、local作用范围
git add 提交命令

3. Through several commits to recognize the work area and the temporary area

Insert picture description here

添加到暂存区:
     git add
提交:
    git commit
    git add -u(全部提交)

4. Convenient way to rename files in git

将readme的文件名重命名为--->readme.md

General operation
Insert picture description here
Simple operation

为了重新演示简便的操作,在此我们将git的状态进行复原:
清理掉暂存区、工作路径上的所有变更
    git reset --hard

Insert picture description hereInsert picture description here

5. View the history of version evolution through git log

git log 当前分支的版本演变历史
git log -all --graph
git log --oneline 
git log --oneline -all    
git log --oneline -all  -n4(取最近的4个commit)
git log --oneline -all  -n4 -graph
-->gitk:通过图形界面工具来查看版本历史

6 .–> gitk: View the version history through the graphical interface tool

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200316213213457.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xlYWVhc29u,size_16,color_FFFFFF,t_70)

-->gitk:通过图形界面工具来查看版本历史

7. What is in the git folder (it is a hidden file, ls -al to view)

lee@DESKTOP-DVA0RLQ MINGW64 /e/Git/WorkSpace/huashan/.git (GIT_DIR!)
$ ls -al
total 13
drwxr-xr-x 1 lee 197121   0  3月 14 09:06 ./
drwxr-xr-x 1 lee 197121   0  3月 12 20:21 ../
-rw-r--r-- 1 lee 197121  12  3月 12 20:22 COMMIT_EDITMSG
-rw-r--r-- 1 lee 197121 243  3月 14 09:06 config
-rw-r--r-- 1 lee 197121  73  3月 12 20:20 description
-rw-r--r-- 1 lee 197121  23  3月 12 20:20 HEAD
drwxr-xr-x 1 lee 197121   0  3月 12 20:20 hooks/
-rw-r--r-- 1 lee 197121 145  3月 12 20:22 index
drwxr-xr-x 1 lee 197121   0  3月 12 20:20 info/
drwxr-xr-x 1 lee 197121   0  3月 12 20:22 logs/
drwxr-xr-x 1 lee 197121   0  3月 12 20:22 objects/
drwxr-xr-x 1 lee 197121   0  3月 14 09:18 refs/
HEAD,文本文件,它是一个引用,指向分支。等同于切换分支命令git checkout

Insert picture description here
Insert picture description here

config,用户名和邮箱配置文件

Insert picture description here
refs, which stores the information of each branch and tags
Insert picture description here

8. The relationship between the three objects of commit, tree and blob

objects,也是一个文件夹,里面包含三个对象,这也是git中核心的三个对象
    blob,文件内容相同,blob就都一样
    tree
    commit

Insert picture description here

9. Matters needing attention in the case of separating the head pointer

需要跟某个分支绑定在一起

10. How to delete unnecessary branches?

git branch -D fix_readme(清理掉fix_readme这个不用的分支)
gt branch -v(查看剩下的分支)

11. How to modify the message of the latest commit?

Insert picture description here
Insert picture description here

12. How to modify the message of the old commit?

Insert picture description here

git  rebase -i 版本的hash值

Insert picture description here

wq,保存并退出

Insert picture description here

基于自己的分支的变基操作,当已经共享出去的内容,则不可随意做变基。

13. How to organize consecutive commits into one?

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

14. How to compare the difference between the files in the temporary storage area and HEAD?

git diff --cached  比较暂存区的差异

15. How to compare the differences between the files in the work area and the temporary storage area?

git diff ,比较的是工作区和暂存区之间的差异
git diff --具体的文件名,比较的是具体的文件在工作区和暂存区之间的差异。

Insert picture description here

16 丨 How to restore the files in the working area to the same as the temporary storage area?

The changes made in the staging area are not wanted, and they are consistent with HEAD.

17 丨 How to restore the files in the working area to the same as the temporary storage area?

工作区所做的变更不再生效,将其还是与已经添加到暂存区所做的变更一致。
git chechout 

18 丨 Eliminate recent commits

git reset --hard +hash码
删除某些不想要的文件
git rm filename

19 丨 How to specify files that do not need to be managed by Git?

.ignore配置文件中的文件类型都不纳入到版本控制管理中
配置仓库时候,可以导入.ignore文件

20 丨 How to backup Git warehouse to local?

将变更同步到远端仓库:
git remote -v

21 丨 Configure public and private keys

公钥添加到Github账号
生成秘钥

So far, you can complete basic Git-based project management.
It will be useful for further study in the future, so that the efficiency will be higher.

reference

Baidu SkyDrive: Shang Silicon Valley Github learning materials, extraction code: 5jh4

Published 34 original articles · praised 4 · 30,000+ views

Guess you like

Origin blog.csdn.net/leaeason/article/details/104909924