git真的是一个代码管理神器,帮助我们在代码开发过程中更好的进行版本管理,如果没有版本管理器,就要不停的复制粘贴,一个项目开发下来,一堆的版本文件夹,最后都不知道是哪个版本了。
用git之后,每一次的提交都会记录在册,随时查看完成了哪些功能,代码发生了哪些变动,回退到任何一个版本,所以即便是不把代码提交到远程服务器,在自己本地进行管理,也是非常非常棒的!
在本地进行版本管理的步骤如下:
1.建立一个空的项目文件夹test,在文件夹下打开git bash 命令窗,输入命令
git init
2.在文件夹下添加代码,利用如下命令,就可以把代码提交到本地仓库了。
git add //代码添加到缓存区 git status //查看状态,是否要添加到缓存区的代码已经添加成功 git commit -m”更改说明” //代码提交到本地仓库
3.查看修改记录
git log 查看提交过的版本信息,看不出来被删除的记录,和被回退的记录
git log --pretty=oneline 只会显示版本号和提交时的备注信息
git reflog 查看所有分支的所有操作记录,包括已经被删除的记录和 reset 的操作,还有回退记录
4.回退版本
git reset --hard HEAD^
:回退到上一版;git reset --hard HEAD^^
:回退到倒数第二版;git reset --hard 修改记录id
:回退到修改记录id的版本;