单机上使用 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"
本文介绍了如何在单机上安装并使用Git,包括初始化仓库、添加代码、提交、查看状态、回滚版本、查看历史记录及恢复文件等基本操作。
657

被折叠的 条评论
为什么被折叠?



