git - 查看已暂存和未暂存的更新以及文件修改之后暂存区、上次提交过的不同
2015-04-10 10:35
197 查看
实际上
假如再次修改
要查看尚未暂存的文件更新了哪些部分,不加参数直接输入
此命令比较的是工作目录中当前文件和暂存区域快照之间的差异,也就是修改之后还没有暂存起来的变化内容。
若要看已经暂存起来的文件和上次提交时的快照之间的差异,可以用
请注意,单单
像之前说的,暂存 benchmarks.rb 后再编辑,运行
现在运行
然后用
[/code]
git status的显示比较简单,仅仅是列出了修改过的文件,如果要查看具体修改了什么地方,可以用
git diff命令。稍后我们会详细介绍
git diff,不过现在,它已经能回答我们的两个问题了:当前做的哪些更新还没有暂存?有哪些更新已经暂存起来准备好了下次提交?
git diff会使用文件补丁的格式显示具体添加和删除的行。
假如再次修改
README文件后暂存,然后编辑
benchmarks.rb文件后先别暂存,运行
status命令将会看到:
$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: README 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: benchmarks.rb
要查看尚未暂存的文件更新了哪些部分,不加参数直接输入
git diff:
$ git diff diff --git a/benchmarks.rb b/benchmarks.rb index 3cb747f..da65585 100644 --- a/benchmarks.rb +++ b/benchmarks.rb @@ -36,6 +36,10 @@ def main @commit.parents[0].parents[0].parents[0] end + run_code(x, 'commits 1') do + git.commits.size + end + run_code(x, 'commits 2') do log = git.commits('master', 15) log.size
此命令比较的是工作目录中当前文件和暂存区域快照之间的差异,也就是修改之后还没有暂存起来的变化内容。
若要看已经暂存起来的文件和上次提交时的快照之间的差异,可以用
git diff --cached命令。(Git 1.6.1 及更高版本还允许使用
git diff --staged,效果是相同的,但更好记些。)来看看实际的效果:
$ git diff --cached diff --git a/README b/README new file mode 100644 index 0000000..03902a1 --- /dev/null +++ b/README2 @@ -0,0 +1,5 @@ +grit + by Tom Preston-Werner, Chris Wanstrath + http://github.com/mojombo/grit + +Grit is a Ruby library for extracting information from a Git repository
请注意,单单
git diff不过是显示还没有暂存起来的改动,而不是这次工作和上次提交之间的差异。所以有时候你一下子暂存了所有更新过的文件后,运行
git diff后却什么也没有,就是这个原因。
像之前说的,暂存 benchmarks.rb 后再编辑,运行
git status会看到暂存前后的两个版本:
$ git add benchmarks.rb $ echo '# test line' >> benchmarks.rb $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: benchmarks.rb 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: benchmarks.rb
现在运行
git diff看暂存前后的变化:
$ git diff diff --git a/benchmarks.rb b/benchmarks.rb index e445e28..86b2f7c 100644 --- a/benchmarks.rb +++ b/benchmarks.rb @@ -127,3 +127,4 @@ end main() ##pp Grit::GitRuby.cache_client.stats +# test line
然后用
git diff --cached查看已经暂存起来的变化:
$ git diff --cached diff --git a/benchmarks.rb b/benchmarks.rb index 3cb747f..e445e28 100644 --- a/benchmarks.rb +++ b/benchmarks.rb @@ -36,6 +36,10 @@ def main @commit.parents[0].parents[0].parents[0] end + run_code(x, 'commits 1') do + git.commits.size + end + run_code(x, 'commits 2') do log = git.commits('master', 15) log.size
[/code]
相关文章推荐
- git 分支的 创建 修改 切换 查看 从远程仓库抓取数据 以及 提交时忽略某文件
- Git学习(三)----文件查看修改、提交修改
- git 查看某一个文件的(提交/修改)记录
- git中如何查看一个文件的修改(更新)历史
- git查看某一次提交修改的文件列表
- git - 查看某次提交某个文件的修改
- Git入门指南五:查看已暂存和未暂存的更新/提交更新
- git - 查看文件是否提交以及是否提交到远程服务器
- git创建版本库、提交修改文件、查看修改文件
- Git 使用教程(一):安装以及文件的提交和修改
- Git 文件的修改提交与历史记录查看(02)
- Git查看某一个文件的修改记录(提交记录)
- git 用法以及命令, 修改文件提交命令
- git查看某次提交/更新所更改的文件
- git使用diff----git-pull之后如何查看拉下来的文件有那些修改
- linux查看及修改文件权限以及相关
- git查看某个文件的修改历史
- linux查看及修改文件权限以及相关
- linux 系统 查看文件编码以及修改编码
- linux 查看文件编码以及修改编码