单机上使用git

单机上使用 git

安装git,初始化git仓库

yum install git -y
mkdir /data/gitroot
cd /data/gitroot
git init

在这里插入图片描述
添加代码,提交,查看状态

echo -e "abc\ndef\nghi" > test.file
git add test.file
git commit -m "add test.file v1"
再次修改 test.file
git add test.file
git commit -m "modify test.file v2"
git status

再次修改 test.file,查看状态
在这里插入图片描述
提交之后,查看日志记录

git log

在这里插入图片描述
一行显示日志
在这里插入图片描述
回滚到某个版本

git reset --hard 62140d0c898312394cb4

查看所有历史版本

git reflog

在这里插入图片描述
还原到 这个字符串对应的版本

git reset --hard 8103d4c

在这里插入图片描述

删除了文件,但没有提交还在版本仓库里

rm -rf test.file

还原文件

git checkout -- test.file

在这里插入图片描述

再次修改 test.file,加上标记

echo aaa >> test.file
git add test.file

撤销标记,数据还原到标记前的状态

git reset HEAD test.file
git checkout -- test.file

删除文件

git rm test.file
git commit -m "delete test.file"
发布了112 篇原创文章 · 获赞 6 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/studywinwin/article/details/104788441