⑧. 历史版本 reflog log
- ①. 查看历史版本(git reflog 查看版本信息 | git log 查看版本详细信息)
$ git reflog 272a9cd (HEAD -> master) HEAD@{0}: commit (initial): 第一次提交 a.txt Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git log commit 272a9cde6cd70ec607687b6ce161fc46f8b9de2b (HEAD -> master) Author: o-tangzhi <o-tangzhi@ghac.cn> Date: Sun May 16 17:10:35 2021 +0800 第一次提交 a.txt
②. 版本穿梭(git reset --hard 版本号)
我们在a.txt最后添加了第二次版本
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: a.txt no changes added to commit (use "git add" and/or "git commit -a") Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git add -A warning: LF will be replaced by CRLF in a.txt. The file will have its original line endings in your working directory Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git commit -m "第二次提交了" a.txt warning: LF will be replaced by CRLF in a.txt. The file will have its original line endings in your working directory [master c5d3d8a] 第二次提交了 1 file changed, 1 insertion(+) Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git log commit c5d3d8a380a444650db481f6ea2b84a0a0371716 (HEAD -> master) Author: o-tangzhi <o-tangzhi@ghac.cn> Date: Sun May 16 17:16:19 2021 +0800 第二次提交了 commit 272a9cde6cd70ec607687b6ce161fc46f8b9de2b Author: o-tangzhi <o-tangzhi@ghac.cn> Date: Sun May 16 17:10:35 2021 +0800 第一次提交 a.txt Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git reflog c5d3d8a (HEAD -> master) HEAD@{0}: commit: 第二次提交了 272a9cd HEAD@{1}: commit (initial): 第一次提交 a.txt Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git reset --hard 272a9cd # 注意这里切换到了第一次版本提交 HEAD is now at 272a9cd 第一次提交 a.txt Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git reflog 272a9cd (HEAD -> master) HEAD@{0}: reset: moving to 272a9cd c5d3d8a HEAD@{1}: commit: 第二次提交了 272a9cd (HEAD -> master) HEAD@{2}: commit (initial): 第一次提交 a.txt Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) # 注意这里切换到第二次 $ git reset --hard c5d3d8a HEAD is now at c5d3d8a 第二次提交了 $ cat a.txt hello TANGZHI hello TANGZHI hello TANGZHI hello TANGZHI hello TANGZHI hello TANGZHI hello TANGZHI hello TANGZHI hello TANGZHI 第二次版本迭代
⑨. Git工作目录下文件的两种状态
- ①. untracked 未跟踪(未被纳入版本控制)
- ②. tracked 已跟(被纳入版本控制)
Unmodified 未修改状态
Modified 已修改状态
Staged 已暂存状态
这些文件的状态会随着我们执行Git的命令发生变化
⑩. .gitignore
# no .a files :.a结尾的都要忽略 *.a # !lib.a 不需要忽略 !lib.a # /TODO的这个文件需要忽略 /TODO # build目录下所有的文件都忽略 build/ # doc目录下以.txt文件的都要忽略 doc/*.txt # doc目录下所有或子目录下所有的.pdf文件都要忽略 doc/**/*.pdf