forked from insistMiss/node_pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.txt
119 lines (118 loc) · 6.48 KB
/
git.txt
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
下载地址:
1.https://npm.taobao.org/mirrors/git-for-windows
2.https://git-scm.com/downloads
一.git简介:
1.可以备份,类似于网盘,可以版本控制,每天代码都可以备份,好处是代码不被覆盖
2.我们传统备份:建立文件夹,不停的往里复制,不好管理
3.每天写的代码都有不同的地方,不知道,那就得需要对比
4.相当于打游戏,每天可以存档,打不好会到那个节点,不停的"穿越"
5.多端共享:可以通过手机,PC,安卓,苹果随时随地的工作,在家也可以---有网就行
6.团队协作:可以将多个人的程序进行合并,比如多个人写一个程序,代码合在一起,你得对代码-不科学
7.git有强大的"分支"管理系统
8.git采用的分布式文件处理
9.svn采用集中式文件处理
10.git要比SVN要快
二.git有三个区:
1.工作区:本地代码
2.暂存区/过渡区
3.历史区/版本管理:存在这里不会丢失
三.操作:Administrator@W-20200824XBIIZ MINGW64 ~/Desktop
Administrator:用户名
W-20200824XBIIZ:计算机名称
MINGW64:系统
~:当前用户
/Desktop:位置
(1).配置命令:
$ pwd:当前目录
$ git config --list:查看用户配置列表
配置过:user.name=xxx
user.email=xxx
配置用户信息:
$ git config --global user.name shiyi-1113
$ git config --global user.email 2789227649@qq.com
(2).目录文件操作命令
1.初始化命令(不能嵌套初始化:只在根目录嵌套一遍) $ git init
2.初始化位置有问题,需要删除(也可以右键删除):$ rm -rf .git
rf带有强制性 rm -rf删除的是文件夹
删除的时候注意:$ rm -rf * 这个命令是删除所有文件
3.创建文件夹:$ mkdir 目录名
4.清屏:$ clear
5.进入目录:$ cd 目录名
6.进入某盘:$ cd d:
7.当初始化完成时在目录后会出现:master(代表主分支)
8.查看项目目录(相当于dir/w):$ ls
9.显示详细的目录信息(相当于dir):$ ls -al
10.创建文件:$ touch 文件名.类型
11.查看文件内容(相当于type 1.txt):$ cat 1.txt
12.进入文件:$ vi 1.txt
i:编辑
按一下Esc,然后输入 :wq 保存退出 :q!不保存退出
(3).文件提交
1.$ git status 查看状态--->红色(未提交),绿色(已提交)
2.$ git add . 将所有文件提交到暂存区
$ git add -A 将所有文件提交到暂存区
$ git add 1.txt 将单个文件提交到暂存区
3.$ git rm --cached . -r 将暂存区的所有文件删除(退回到工作区)
4.提交的时候不能从工作区直接提交到历史区
$ git commit -m 'root' -m 消息,必须添加,空不可以,没有也不行
工作区--->暂存区--->历史区
5.$ git log 查看历史区
(4).工作区\缓存区\历史区 对比
1.$ git diff 工作区和暂存区,如果相同不会提示 --没有
2.$ git diff master 工作区和历史区
3.$ git diff --cached 暂存区和版本区对比
(5).撤销
1.$ git checkout . 撤销所有文件:暂存区->工作区
$ git checkout -- 1.txt 撤销单个文件:暂存区->工作区
2.提交到暂存区->撤销:$ git checkout .->又提交->再撤销(回滚)->$ git reset HEAD .
(6).git commit -a -m '消息' 直接从工作区提交到历史区,条件是此文件以前就提交过历史区
(7).历史区回滚到工作区
1.git reset --hard commit号码(复制7位以上) 历史区回滚到工作区(穿越) ---回到过去
2.git reflog 查看历史记录,复制号码
git reset --hard 号码(要最近日期的) ---回到现在
(8).分支:多人开发,需要创建分支,最后将分支给合并成一个项目
1、查看分支:git branch 目前有一个主分支master
2、创建分支:git branch 名称
3、切换分支:*是当前所在分支, git checkout 名称
4、当你用git log的时候发现:现在创建分支具备了master所有内容
5、删除分支,不能删除当前分支(因为正在使用中) git branch -D 分支名称(-D可以小写)
6、创建并切换:git checkout -b 分支名(创建git branch 和切换git checkout合成一个命令)
(9).分支操作
1、切换分支:git checkout dev
2、在分支dev创建了一个文件2.js:touch 2.js
按理说master应该是看不到的,但是它在master分支也是可以看到的,我们现在创建的都是公共的
3、这dev这个分支上,提交到了缓存区,这时切换到master还是能看到dev创建的文件,
4、在dev分支上提交到历史区,这个时候才能独立
切换到dev分支,提交到历史区:git commit -m 'add 2.js' ,ls 查看
切换到master分支查看,ls发现2.js没有了
(10).分支合并
1、切换到主分支,现在是dev分支的版本要高于master,通过git log来查看
2、git merge dev 将dev分支合并到主分支,怎么证明你合并成功了,通过ls来查看,原来的2.js在marster分支下是看不见的,如果能合并成功,就可以看见。
练习:
1、再分支上创建的文件,只有提交到历史区,才属于自己分支的。
2、 git commit -a -m 'first' ,一次也没有哦提交到历史区,只能先提交到暂存区,(第一次是不能一次性提交到历史区的,只能先提交到暂存区)
3、创建文件: echo 内容>2.txt //将内容方到刚创建的2.txt中
远程仓库:
1、只有本地的历史区才能提交到github上,其他区是不可以的,尤其是工作区
2、创建项目,项目中有一个readme.md文件,描述文件,描述项目的。
3、rm -rf .idea 删除文件的
4、有些文件不想删除,但是也不想上传,先创建一个配置文件 .gitignore文件
写入不想上传的文件名称
5、创建远程仓库:
将你的项目推到位置上
git remote add origin https://github.com/insistMiss/node_pro.git
添加到orinin这个仓库中
git push -u origin main
6、本地和仓库创建关联:
1、添加到暂存区,git add .
2、提交到历史区 git commit -m 'root'
3、git remote add origin https://github.com/insistMiss/node_pro.git 指定提交的位置
4、查看远程信息 git remote -v
origin https://github.com/insistMiss/node_pro.git (fetch) 抓取
origin https://github.com/insistMiss/node_pro.git (push)添加
5、git push origin master
6、当我们上线了修改了,线下也修改了,我们这时不能直接push,而是需要拉取,然后修改,在上传
1、git pull origin master
2、修改本地的(可以添加文件,注意冲突的文件)
3、git add . git commit -m 'xxx'
4、git push origin master