-
初始化
git init
-
新建一个文件
vim <file>
eg: vim good.txt
-
状态查看
git status
-
当文件夹中无加载内容时候,会出现以下提示:
$ git status starting fsmonitor-daemon in 'D:/学习资料/git' error: could not spawn fsmonitor--daemon in the background On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) good.txt nothing added to commit but untracked files present (use "git add" to track)
-
将工作区的“新建/修改” 添加到暂存区
git add [file name]
eg: git add good.txt
-
从暂存区里删除,并没有从文件夹中删除
*git rm --cached <file>*
eg: git rm --cached good.txt
-
暂存区到本地库
git commit <文件名> git commit -m '记录操作的意义' <file>
eg: git commit good.txt 或者 git commit -m 'my second commit,modify' good.txt
他俩的区别是是否跳出一个新的vim界面来记录代码相关信息如果使用git commit good.txt接着会出现这个界面(可以记录这次操作的意义):
我的界面用vscode打开了,如果想在想将默认编辑器改为vim,可以用下面的命令。 -
git config --global core.editor 'vim'
就变成了下图:
:set nu可以显示行号
在第一行后面添加一些备注
如果使用git commit -m ‘mysecond…’ good.txt接着会出现这个界面(可以记录这次操作的意义):
:wq!退出即可,出现master。。。。就成功了
上图中7insertions表示good.txt文件添加了7行。可以通过cat 查看,我的里面还有四行空白,所以是七行
提交到本地库之后的git status:
如果good.txt文件被修改了查看git status,系统检测到后,有两种解决方法:
1. 重新提交git add <file>或者 git commit <file>
2. 回到之前版本git restore <file>
- 查看历史版本
git log