git工具使用:
Git特点:
1.速度
2.简单的设计
3.对非线性开发模式的强力支持(允许成千上万个并行开发的分支)
4.完全分布式
5.有能力高效管理类似 Linux 内核一样的超大规模项目(速度和数据量)
Git 有三种状态:已提交(committed)、已修改(modified) 和 已暂存(staged)。
1.已修改表示修改了文件,但还没保存到数据库中。
2.已暂存表示对一个已修改文件的当前版本做了标记,使之包含在下次提交的快照中。
3.已提交表示数据已经安全地保存在本地数据库中。
这会让我们的 Git 项目拥有三个阶段:工作区、暂存区以及 Git 目录
[[email protected] ~]# yum install -y git ##安装
[[email protected] ~]# mkdir demo ##创建仓库
[[email protected] demo]# git init ##仓库初始化
练习:
提交:
[[email protected] demo]# touch README
[[email protected] demo]# git status -s ##查看状态
[[email protected] demo]# git add README ##添加文件
[[email protected] demo]# git status -s ##暂存区
[[email protected] demo]# git commit -m "add README" ##提交
[[email protected] demo]# git config --global user.email "[email protected]"
[[email protected] demo]# git config --global user.name "yy"
[[email protected] demo]# git commit -m "add README" ##提交缓存内容
[[email protected] demo]# git status -s ##当前文件未修改
[[email protected] demo]# echo westos > README
[[email protected] demo]# git status -s
[[email protected] demo]# echo westos >> README
[[email protected] demo]# git checkout -- README ##撤销
[[email protected] demo]# echo westos > README
[[email protected] demo]# git status -s ##右边 缓存区 在工作区修改
[[email protected] demo]# git add README
[[email protected] demo]# git status -s ##左边 暂存区
[[email protected] demo]# git add . ##添加目录文件
[[email protected] demo]# git commit -m "v1" ##提交
忽略文件:
[[email protected] demo]# touch .a
[[email protected] demo]# touch .o
[[email protected] demo]# git status -s
[[email protected] demo]# mkdir env
[[email protected] demo]# git status -s
[[email protected] demo]# cd env/
[[email protected] env]# touch values
[[email protected] env]# git status -s
[[email protected] env]# cd ..
[[email protected] demo]# vim .gitignore ##忽略隐藏文件 忽略 env
[[email protected] demo]# git status -s
[[email protected] demo]# echo westos >> README
[[email protected] demo]# git diff ##比对
[[email protected] demo]# git commit -a -m "v3"
[[email protected] demo]# git log ##查看历史
删除文件:
方一:
[[email protected] demo]# rm -f testfile
[[email protected] demo]# git status -s
[[email protected] demo]# git rm testfile
[[email protected] demo]# git commit -a -m "v4"
方二:
[[email protected] demo]# git rm README
[[email protected] demo]# git commit -a -m "v5" ##同步版本库
重命名文件:
mv README.md README
git rm README.md
git add README
查看提交历史:
[[email protected] demo]# git log --pretty=oneline
[[email protected] demo]# git reflog
版本回退:
[[email protected] demo]# git reset --hard 61e3c51
取消暂存的文件:
[[email protected] demo]# git reset --hard ab73b7c
[[email protected] demo]# vim testfile
[[email protected] demo]# git status -s
[[email protected] demo]# git reset HEAD testfile ##取消暂存的文件
撤销:
[[email protected] demo]# git checkout -- testfile ##撤销