学习目的
- 如何跟踪修改文件?
- 如何管理修改文件?
查看当前工作区、暂存区、分支状态
- 工作区
$ cat readme.txt
Git is a version control system.
Git is free software.
Git is a distributed version control system.
Git is free software.
添加一行测试工作区、暂存区、分支。
cat 命令测试。
- 暂存区
$ git status
On branch master
nothing to commit, working tree clean
- 分支
$ git log
commit 3b8f1b20d0c3e238f413076c4f4715910156f570 (HEAD -> master)
Author: Rattenking <1148063373@qq.com>
Date: Sat Sep 29 14:14:19 2018 +0800
cat命令测试
commit 500dceab4bd5261c3fd9acd65df90d4e653d2047
Author: Rattenking <1148063373@qq.com>
Date: Sat Sep 29 11:35:05 2018 +0800
提交工作区、暂存区、分支测试
commit e2addc717e8e35a61c1748219095b06fd9cbff46
Author: Rattenking <1148063373@qq.com>
Date: Fri Sep 28 16:54:05 2018 +0800
添加了两句话
commit 101462868fcc996bd42169709499dbd33975847c
Author: Rattenking <1148063373@qq.com>
Date: Fri Sep 28 14:30:41 2018 +0800
wrote a readme file
现在我们已经清楚初始各个区的状态!
修改文件跟踪各区状态
- 修改文件工作区
$ cat readme.txt
Git is a version control system.
Git is free software.
Git is a distributed version control system.
Git is free software.
添加一行测试工作区、暂存区、分支。
cat 命令测试。
测试修改文件后各区状态!
- 修改文件暂存区
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
- 修改文件分支
$ git log --pretty=oneline
3b8f1b20d0c3e238f413076c4f4715910156f570 (HEAD -> master) cat命令测试
500dceab4bd5261c3fd9acd65df90d4e653d2047 提交工作区、暂存区、分支测试
e2addc717e8e35a61c1748219095b06fd9cbff46 添加了两句话
101462868fcc996bd42169709499dbd33975847c wrote a readme file
将修改文件添加到暂存区
$ git add readme.txt
- 添加到暂存区的时候工作区
$ cat readme.txt
Git is a version control system.
Git is free software.
Git is a distributed version control system.
Git is free software.
添加一行测试工作区、暂存区、分支。
cat 命令测试。
测试修改文件后各区状态!
- 添加到暂存区的时候暂存区
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: readme.txt
- 添加到暂存区的时候分支
$ git log --pretty=oneline
3b8f1b20d0c3e238f413076c4f4715910156f570 (HEAD -> master) cat命令测试
500dceab4bd5261c3fd9acd65df90d4e653d2047 提交工作区、暂存区、分支测试
e2addc717e8e35a61c1748219095b06fd9cbff46 添加了两句话
101462868fcc996bd42169709499dbd33975847c wrote a readme file
将修改文件提交到分支
$ git commit -m "测试管理修改提交"
[master 5cc8766] 测试管理修改提交
1 file changed, 2 insertions(+), 1 deletion(-)
- 提交修改文件后工作区
$ cat readme.txt
Git is a version control system.
Git is free software.
Git is a distributed version control system.
Git is free software.
添加一行测试工作区、暂存区、分支。
cat 命令测试。
测试修改文件后各区状态!
- 提交修改文件后暂存区
$ git status
On branch master
nothing to commit, working tree clean
- 提交修改文件后分支
$ git log --pretty=oneline
5cc8766c378c412c3f6f476c57987aadc344f426 (HEAD -> master) 测试管理修改提交
3b8f1b20d0c3e238f413076c4f4715910156f570 cat命令测试
500dceab4bd5261c3fd9acd65df90d4e653d2047 提交工作区、暂存区、分支测试
e2addc717e8e35a61c1748219095b06fd9cbff46 添加了两句话
101462868fcc996bd42169709499dbd33975847c wrote a readme file
查看修改前后工作区和版本库最新版本的区别
- 修改前
$ git diff
- 修改后
$ git diff
diff --git a/readme.txt b/readme.txt
index 29c21cd..7cf2360 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,4 +4,5 @@ Git is a distributed version control system.
Git is free software.
添加一行测试工作区、暂存区、分支。
cat 命令测试。
-测试修改文件后各区状态!
No newline at end of file
+测试修改文件后各区状态!
+测试git diff,查看工作区和分支文件的修改情况!
No newline at end of file
小结
- 跟踪修改文件(git status),通过查看工作区的状态,来查看文件是否被添加到暂存区,是否被提交到分支。
- 每次文件的修改都必须进行将文件添加到暂存区(git add),提交修改文件(git commit)时才能提交到分支。
- git diff对比工作区和版本库最新版本的区别!
其他
QQ交流群: 264303060