一、提交文件方面命令:
1.1第一步:将需要提交的文件放进暂存区:
-
添加单个文件到暂存区stage:
git add 文件名
![](https://file.jishuzhan.net/article/1794776760332587009/2b408459a431abb140ff14cca264bad8.webp)
-
添加多个文件到暂存区:
git add 文件名1 文件名2 ...
![](https://file.jishuzhan.net/article/1794776760332587009/e2508cc1028ff7a37414634259952d77.webp)
-
将目录下所有文件添加到暂存区:
git add .
![](https://file.jishuzhan.net/article/1794776760332587009/91074bd873bf747fb5a85ece94fcf1f1.webp)
1.2第二步:将缓冲区的文件添加到版本库:
git commit -m "本次提交方面的详细描述"
![](https://file.jishuzhan.net/article/1794776760332587009/e763322badb3b4baf85ff18a8094826a.webp)
1.3第三步:将本地仓库的文件同步至远程仓库:
git push
二、查看仓库信息方面命令:
2.1日期由近到远的打印版本库的提交日志:
-
详细的打印所有信息:
git log
![](https://file.jishuzhan.net/article/1794776760332587009/3c95ce317290ac6d29e0311ece0f3068.webp)
-
以一行的方式打印部分信息:
git log --pretty=oneline
![](https://file.jishuzhan.net/article/1794776760332587009/d665979d1caa1ea96d6b966192d4ecde.webp)
2.2查看工作区和暂存区的状态:
-
查看工作区是否干净,例如文件没有push或commit等:
git status
![](https://file.jishuzhan.net/article/1794776760332587009/a619246b33e6465fa3309b83aacd57ec.webp)
![](https://file.jishuzhan.net/article/1794776760332587009/6d8ec15ae5e49ceccc258de32df4a90b.webp)
2.3对比文件在不同区域的差异:
-
暂存区和工作区之间的差异:
git diff 文件名
![](https://file.jishuzhan.net/article/1794776760332587009/fb05ee6988ce2a31a7fb2df75e6d171b.webp)
-
版本库和工作区之间的差异:
git diff HEAD -- 文件名
![](https://file.jishuzhan.net/article/1794776760332587009/ffc83a5442d9edc8b9969e6117cb491c.webp)
三、文件版本回退方面命令:
git reset
是一个强大的 Git 命令,用于回退当前分支的HEAD指针到一个指定的提交。
3.1只回退版本库中的版本:
git reset --soft commitID
3.2回退暂存区和版本库中的内容:如果不指定选项,默认使用mixed
git reset --mixed commitID
3.3回退三个区域的内容:
git reset --hard commitID
案例分析:使用hard需要谨慎
![](https://file.jishuzhan.net/article/1794776760332587009/c85dcbb2d1585dccff6d94ce00ea148e.webp)
![](https://file.jishuzhan.net/article/1794776760332587009/235e4543e5aa468db2578d0ca02df78a.webp)
![](https://file.jishuzhan.net/article/1794776760332587009/9753550d6ab6f37222ce37051caa1636.webp)
3.4找到曾经存在的提交记录:
-
Git Reflog 是 Git 的一个工具,用于记录所有对仓库的引用(ref)的更改。即使在引用被移动或删除后,Reflog 也能帮助你找到那些曾经存在的提交记录。
git reflog
![](https://file.jishuzhan.net/article/1794776760332587009/4b8a119a5d2bffb3d09131d3701e1ed9.webp)
- 使用git reset --选项 ID,可以回到指定节点。