Git 学习札记(三)关于 git diff 操作及其参数
2018-02-07 16:26
387 查看
Git 学习札记(三)
关于Git中diff操作的比较
git diff ,git diff –cached,git diff –staged,git diff HEAD – filename
先做一个实验:chia@edogawachia-sphinx:~/mygit$ cat readme.txt This is a readme file created by E.Chia 2018/02/06 modified by E.Chia 1st time chia@edogawachia-sphinx:~/mygit$ git status 位于分支 master 无文件要提交,干净的工作区 chia@edogawachia-sphinx:~/mygit$ sudo vim readme.txt chia@edogawachia-sphinx:~/mygit$ cat readme.txt This is a readme file created by E.Chia 2018/02/06 modified by E.Chia 1st time add this to show staged version chia@edogawachia-sphinx:~/mygit$ sudo git add 'readme.txt' chia@edogawachia-sphinx:~/mygit$ git status 位于分支 master 要提交的变更: (使用 "git reset HEAD <文件>..." 以取消暂存) 修改: readme.txt chia@edogawachia-sphinx:~/mygit$ sudo vim readme.txt chia@edogawachia-sphinx:~/mygit$ cat readme.txt This is a readme file created by E.Chia 2018/02/06 modified by E.Chia 1st time add this to show staged version add this to show working directory version
这样三个区域的版本都不一样了,branch中的最短,stage暂存区的有一句add this to show staged version,工作区的多一句 add this to show working directory version。
下面测试各种 diff 的用法:
chia@edogawachia-sphinx:~/mygit$ git diff diff --git a/readme.txt b/readme.txt index 3e42036..e24b3e0 100644 --- a/readme.txt +++ b/readme.txt @@ -2,3 +2,4 @@ This is a readme file created by E.Chia 2018/02/06 modified by E.Chia 1st time add this to show staged version +add this to show working directory version chia@edogawachia-sphinx:~/mygit$ git diff --cached diff --git a/readme.txt b/readme.txt index d995350..3e42036 100644 --- a/readme.txt +++ b/readme.txt @@ -1,3 +1,4 @@ This is a readme file created by E.Chia 2018/02/06 modified by E.Chia 1st time +add this to show staged version chia@edogawachia-sphinx:~/mygit$ git diff --staged diff --git a/readme.txt b/readme.txt index d995350..3e42036 100644 --- a/readme.txt +++ b/readme.txt @@ -1,3 +1,4 @@ This is a readme file created by E.Chia 2018/02/06 modified by E.Chia 1st time +add this to show staged version chia@edogawachia-sphinx:~/mygit$ git diff HEAD diff --git a/readme.txt b/readme.txt index d995350..e24b3e0 100644 --- a/readme.txt +++ b/readme.txt @@ -1,3 +1,5 @@ This is a readme file created by E.Chia 2018/02/06 modified by E.Chia 1st time +add this to show staged version +add this to show working directory version chia@edogawachia-sphinx:~/mygit$ git diff HEAD -- readme.txt diff --git a/readme.txt b/readme.txt index d995350..e24b3e0 100644 --- a/readme.txt +++ b/readme.txt @@ -1,3 +1,5 @@ This is a readme file created by E.Chia 2018/02/06 modified by E.Chia 1st time +add this to show staged version +add this to show working directory version
可以看到,git diff 比较工作区和暂存区,git diff –cache (或者–staged)比较版本和暂存区,git diff HEAD – filename 比较branch上的HEAD指向的版本与工作区的区别(这里的HEAD可以是任意指针,即用哈希值表示的 commit id ,或者HEAD~等)。这样三者中的任意两者都可以比较了。
2018-02-07 16:25:46
相关文章推荐
- 【Scikit-Learn 中文文档】四十六:模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】46 模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- Git 学习札记(二)安装git以及基本操作
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- git学习-git status, git diff, git rm, git mv等文件操作命令解释。
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- 【Scikit-Learn 中文文档】模型选择:选择估计量及其参数 - 关于科学数据处理的统计学习教程 - scikit-learn 教程 | ApacheCN
- GitHub入门与实践学习笔记--github学习基础之关于git的基本操作