-
git init 创建git 仓库
cd 到目标文件夹,输入git init,生成一个.git文件夹
-
git status 查看是否有需要待提交的代码或者文件
bobo@ubuntu:~/prectice/studyLinux$ git status
位于分支 master
无文件要提交,干净的工作区
bobo@ubuntu:~/prectice/studyLinux$ git status
位于分支 master
尚未暂存以备提交的变更:
(使用 "git add <文件>..." 更新要提交的内容)
(使用 "git restore <文件>..." 丢弃工作区的改动)
修改: MultipleThread/MyThread.cpp
修改尚未加入提交(使用 "git add" 和/或 "git commit -a")
- git add 选择需要提交的文件
bobo@ubuntu:~/prectice/studyLinux$ git add . #git add . 选中所有待提交文件
bobo@ubuntu:~/prectice/studyLinux$ git status
位于分支 master
要提交的变更:
(使用 "git restore --staged <文件>..." 以取消暂存)
修改: MultipleThread/MyThread.cpp
- git commit 提交文件
bobo@ubuntu:~/prectice/studyLinux$ git commit -m "测试2" #-m "测试2" 提交注释
[master 762f6f0] 测试2
1 file changed, 1 insertion(+), 1 deletion(-)
bobo@ubuntu:~/prectice/studyLinux$ git status
位于分支 master
无文件要提交,干净的工作区
bobo@ubuntu:~/prectice/studyLinux$
- git show 显示文件
需要与git log 配合使用
我们首先,使用 git log 命令,查看 git 的提交日志列表,具体命令如下:
git log
执行完毕后,如下图所示:
bobo@ubuntu:~/prectice/studyLinux$ git log
commit 762f6f059872e2bd0c034909e9cfd33d16e97323 (HEAD -> master)
Author: bobo <2307460652@qq.com>
Date: Sat Mar 9 18:02:29 2024 -0800
测试2
commit d4f808d7a468478cc007e718e565894bcd6a1593
Author: bobo <2307460652@qq.com>
Date: Sat Mar 9 17:24:11 2024 -0800
测试
commit 07d1e331f14c2152ef3446c2168f4e7d416d83c3
Author: bobo <2307460652@qq.com>
Date: Sat Mar 9 17:17:07 2024 -0800
单个线程测试
commit 2883ef1103b320715f018fcc1432f5e1bf0a5638
Author: bobo <2307460652@qq.com>
Date: Sat Mar 9 16:35:00 2024 -0800
建立版本管理
现在,我们使用 git show 命令,查看某次提交某个文件的修改详情,具体命令如下:
git show d4f808d7 MultipleThread/MyThread.cpp
注意:d4f808d7就是从git log 中的某一ID
执行完毕后,如下图所示: