一.下载Git,并安装。
- windows: https://git-for-windows.github.io/
- Linux: apt-get install git
二.具体使用及命令
1.查看是否安装成功 :git

2.创建本地仓库
新建一个文件夹,右键点击Git Bash Here

输入命令:git init,这个文件夹就变成了一个仓库

这个仓库现在是空的没有文件,我们先添加个text.md文件

3.增加一个文件,分两步走:先添加,再提交
.添加:git add text.md(如果要添加全部文件用.代替)
查看文件的状态:git status

如果想撤销add,命令:git reset
如果想提交全部文件,命令:git add .
.提交:git commit -m'first'
(first是我这次提交的说明,自己任意修改)

4.修改文件,上传仓库
把text文件里面添加些内容,然后保存。

git status 提示我们text.md被修改了,但是没有提交

.查看被修改内容,命令:git diff
这里可以看到,我们修改的内容展示出来了

然后我们再进行上面的步骤,add 和commit

.查看我们提交的记录,命令:git log
这是就看到我们两次提交的记录first和second
5.退回到上一个版本的文件
.命令:git reset --hard HEAD^
(假如是上上版本就是HEAD^^,假如是100以前的版本就是HEAD~100)

6.找回被撤销的文件,
打印提交命令记录:git reflog

我们提交second的 id是 dc0aba
.撤回被取消的版本:git reset dc0aba
second又回来了。
7.从版本库里恢复一个文件到文件夹,命令:git checkout text.md
8.从版本库里删除一个文件:命令: git rm text.md
9.关系图

网友评论