0%

Git学习详细记录

Git的必要配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge
$ git config -l
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.email=eminemgcxwlp@gmail.com
user.name=GCXWLP

shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge
$ git config --system --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master

shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge
$ git config --global --list
user.email=eminemgcxwlp@gmail.com
user.name=GCXWLP

Git的工作原理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
+-----------------+        git push         +-----------------+
| Remote Directory| <--------------------- | History |
+-----------------+ +-----------------+
^ ^
| |
| git pull | git reset
| |
v |
+-----------------+ git commit +-----------------+
| History | <--------------------- | Stage(Index) |
+-----------------+ +-----------------+
^
|
git add files |
|
v
+-----------------+
| Working Directory|
+-----------------+
^
|
git checkout |
|
v
+-----------------+
| Stage(Index) |
+-----------------+

基础流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge/gittest
$ git init
Initialized empty Git repository in D:/Edge/gittest/.git/

shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge/gittest (master)
$ ls

shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge/gittest (master)
$ touch whatcanisay.md

shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge/gittest (master)
$ vim whatcanisay.md

shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge/gittest (master)
$ git status
On branch master

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)
whatcanisay.md

nothing added to commit but untracked files present (use "git add" to track)

shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge/gittest (master)
$ git add .

shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge/gittest (master)
$ git status
On branch master

No commits yet

Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: whatcanisay.md


shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge/gittest (master)
$ git commit -m "牢大,坐跑车上学就是爽"
[master (root-commit) 8c62890] 牢大,坐跑车上学就是爽
1 file changed, 1 insertion(+)
create mode 100644 whatcanisay.md

shuaige@DESKTOP-54PIQAR MINGW64 /d/Edge/gittest (master)
$ git status
On branch master
nothing to commit, working tree clean

.gitignore

有些时候我们不想把某些文件纳入版本控制中,比如数据库文件、临时文件、设计文件等。
在主目录下建立 .gitignore 文件,此文件有如下规则:


基本规则

  1. 忽略空行或以 # 开头的行

    • 空行或注释行将被忽略。
  2. 支持 Linux 通配符

    • * :匹配任意多个字符
    • ? :匹配单个字符
    • [abc] :匹配方括号内的任意一个字符
    • {string1,string2,...} :匹配可选的字符串之一
  3. 以感叹号(!)开头的模式表示例外

    • 表示不忽略该文件或目录(即使之前匹配了忽略规则)。
  4. / 开头表示只忽略项目根目录下的文件或目录

    • 子目录中的同名文件不会被忽略。
  5. / 结尾表示忽略目录

    • 默认情况下,会忽略该目录及其子目录中的所有文件。

1
2
3
4
5
6
# 为注释
*.txt # 忽略所有以 .txt 结尾的文件
!lib.txt # 但 lib.txt 不被忽略
/temp # 仅忽略项目根目录下的 temp 文件夹,不包括其他目录下的 temp
build/ # 忽略 build/ 目录中的所有文件
doc/*.txt # 忽略 doc/ 目录下的 .txt 文件,但不包括 doc/server/arch.txt

git分支相关