-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitCommand.txt
119 lines (77 loc) · 3.51 KB
/
GitCommand.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
1、Git Command
1.1、配置每个终端的Name和Email地址:
$ git config --global user.name "Your Name"
$ git config --global user.email "Email@Example.com"
1.2、创建版本库:
$ mkdir GitTutorialLiuJiabin
$ cd GitTutorialLiuJiabin
$ pwd
/e/github/git/GitRepository/GitTutorialLiuJiabin
1.3、 git init命令把目录变成Git可以管理的仓库:
$ git init
Initialized empty Git repository in E:/github/git/GitRepository/GitTutorialLiuJiabin/.git/
1.4、查看当前目录下的文件:
$ ls -ah
./ ../ .git/
1.5、git add 把文件添加到仓库:
$ git add GitCommand.txt
1.6、 git commit提交文件到仓库
$ git commit -m "Git Command Summarize"
1.7、commit可以一次提交很多文件,所以你可以多次add不同的文件,比如:
$ git add file1.txt
$ git add file2.txt file3.txt
$ git add file4.txt
$ git commit -m "add 4 files"
/************************总结以上七点内容***************************************/
初始化一个Git仓库,使用git init命令。
添加文件到Git仓库,分两步:
第一步,使用命令git add <file>,注意,可反复多次使用,添加多个文件;
第二步,使用命令git commit,完成。
1.8、修改GitCommand.txt,运行git status命令查看状态:
$ git status
1.9、git diff命令查看GitCommand.txt修改的内容:
$ git diff GitCommand.txt
2.0、git log命令查看历史记录:
$ git log
2.1、git log添加参数--pretty=oneline,显示为一行:
$ git log --pretty=oneline
2.2、把当前版本回退到上一个版本:
$ git reset --hard HEAD^
2.3、查看文件内容:
$ cat GitCommand.txt
2.4、回到未来指定的某个版本,向上找到指定的版本号:
回到Git Command Summarize modify2版本:
$ git reset --hard f6ada5933018e8fa5c2e15a98f1cdcad68901aa7
HEAD is now at f6ada59 Git Command Summarize modify2
2.5、git reflog用来记录每一次命令
$ git reflog
2.6、查看工作区和版本库里面最新版本的区别:
git diff HEAD -- GitCommand.txt
2.7、修改后 未add(添加到暂存区) 需要撤销修改时:
git checkout -- myfile.txt 或 手动删除工作区修改
2.8、修改后 add了(未commit) 再次修改文件 要撤销第二次修改时:
git checkout -- myfile.txt (将暂存区恢复到工作区)
暂存区有第一次的修改需要commit
2.9、修改后 add了(未commit),需要撤销修改时:
git reset HEAD myfile.txt (将暂存区修改删除)
此时工作区的修改还未撤销
git checkout -- myfile.txt (撤销工作区修改)
3.0、修改后 add并commit了,需要撤销修改时:
git reset --hard HEAD^ (版本回退)
3.1、从版本库中删除该文件,那就用命令git rm删掉,并且git commit:
$ git rm test.txt
$ git commit -m "remove test.txt"
3.2、关联本地仓库:
$ git remote add origin git@gitbub.com:liujiabin1002/GitLearning.git
3.3、把本地库的所有内容第一次推送到远程库上:
$ git push -u origin master
3.4、从现在起,只要本地作了提交,就可以通过命令:
$ git push origin master
把本地master分支的最新修改推送至GitHub,现在,你就拥有了真正的分布式版本库。
3.5、用命令git clone克隆一个本地库:
$ git clone git@github.com:liujiabin1002/DataStructure.git
3.6、
3.7、
3.8、
3.9、
4.0、