Setup and Config
Getting and Creating Projects
Basic Snapshotting
Branching and Merging
Sharing and Updating Projects
Inspection and Comparison
Patching
Debugging
External Systems
Server Admin
Guides
- gitattributes
- Command-line interface conventions
- Everyday Git
- Frequently Asked Questions (FAQ)
- Glossary
- Hooks
- gitignore
- gitmodules
- Revisions
- Submodules
- Tutorial
- Workflows
- All guides...
Administration
Plumbing Commands
- 2.48.1 → 2.49.0 no changes
-
2.48.0
2025-01-10
- 2.46.1 → 2.47.2 no changes
-
2.46.0
2024-07-29
-
2.45.3
2024-11-26
- 2.45.1 → 2.45.2 no changes
-
2.45.0
2024-04-29
- 2.44.1 → 2.44.3 no changes
-
2.44.0
2024-02-23
- 2.43.1 → 2.43.6 no changes
-
2.43.0
2023-11-20
- 2.42.2 → 2.42.4 no changes
-
2.42.1
2023-11-02
-
2.42.0
2023-08-21
- 2.41.1 → 2.41.3 no changes
-
2.41.0
2023-06-01
- 2.40.1 → 2.40.4 no changes
-
2.40.0
2023-03-12
- 2.37.3 → 2.39.5 no changes
-
2.37.2
2022-08-11
- 2.36.1 → 2.37.1 no changes
-
2.36.0
2022-04-18
- 2.35.1 → 2.35.8 no changes
-
2.35.0
2022-01-24
- 2.34.1 → 2.34.8 no changes
-
2.34.0
2021-11-15
- 2.33.1 → 2.33.8 no changes
-
2.33.0
2021-08-16
- 2.32.1 → 2.32.7 no changes
-
2.32.0
2021-06-06
- 2.31.1 → 2.31.8 no changes
-
2.31.0
2021-03-15
- 2.30.1 → 2.30.9 no changes
-
2.30.0
2020-12-27
- 2.29.1 → 2.29.3 no changes
-
2.29.0
2020-10-19
- 2.28.1 no changes
-
2.28.0
2020-07-27
- 2.25.2 → 2.27.1 no changes
-
2.25.1
2020-02-17
-
2.25.0
2020-01-13
- 2.24.1 → 2.24.4 no changes
-
2.24.0
2019-11-04
- 2.22.1 → 2.23.4 no changes
-
2.22.0
2019-06-07
- 2.21.1 → 2.21.4 no changes
-
2.21.0
2019-02-24
- 2.20.1 → 2.20.5 no changes
-
2.20.0
2018-12-09
- 2.19.1 → 2.19.6 no changes
-
2.19.0
2018-09-10
- 2.18.1 → 2.18.5 no changes
-
2.18.0
2018-06-21
- 2.17.1 → 2.17.6 no changes
-
2.17.0
2018-04-02
-
2.16.6
2019-12-06
-
2.15.4
2019-12-06
-
2.14.6
2019-12-06
-
2.13.7
2018-05-22
-
2.12.5
2017-09-22
-
2.11.4
2017-09-22
- 2.10.5 no changes
-
2.9.5
2017-07-30
-
2.8.6
2017-07-30
- 2.7.6 no changes
-
2.6.7
2017-05-05
-
2.5.6
2017-05-05
-
2.4.12
2017-05-05
-
2.3.10
2015-09-28
- 2.1.4 → 2.2.3 no changes
-
2.0.5
2014-12-17
选项
Warning
|
Missing See original version for this content. |
Warning
|
Missing See original version for this content. |
缓存模式
如果指定了 --cached
,则可以询问:
向我显示 HEAD 和当前索引 内容(即我使用 'git write-tree' 写入的内容)之间的差异
举个例子,假设你在工作目录中工作,更新了索引中的一些文件,准备提交。你想知道你 要 提交的内容,而不需要写一个新的树对象并进行比较
git diff-index --cached HEAD
示例:假设我把 commit.c
重命名为 git-commit.c
,并执行了 update-index
使其在索引文件中生效。 由于索引文件与我的工作目录一致,所以`git diff-files`根本不会显示任何内容。但使用 'git diff-index ' 就可以:
torvalds@ppc970:~/git> git diff-index --cached HEAD -100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c +100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c
不难看出,以上是重命名。
事实上,git diff-index --cached
应当 总是完全等同于实际执行 git write-tree 并进行比较。只不过,这个方法更适合只想查看当前位置的情况。
因此,当你问自己 “我已经标记了哪些内容要提交,与之前的树有什么不同” 时,使用 git diff-index --cached
基本上是非常有用的。
非缓存模式
“非缓存” 模式采用的是另一种方法,而且可能是两种模式中最有用的一种,因为它的功能无法用 git write-tree + git diff-tree 来模拟。因此这是默认模式。 非缓存版本提出的问题是:
向我显示 HEAD 与当前已签出树之间的差异 - 索引内容 _ 和未更新的文件
这显然也是一个非常有用的问题,因为它会告诉你*可能*提交的内容。同样,输出结果与 git diff-tree -r 的输出结果完全吻合,但又有所变化。
问题在于,如果某个文件与索引不匹配,我们就不会为它建立备份存储,我们会使用 “全零” sha1 来显示这一点。比方说,你编辑了 kernel/sched.c
,但实际上还没有执行 git update-index --没有与新状态相关联的 “对象”,你就会得到:
torvalds@ppc970:~/v2.6/linux> git diff-index --abbrev HEAD :100644 100644 7476bb5ba 000000000 M kernel/sched.c
也就是说,它显示树已经改变,而且 kernel/sched.c
不是最新的,可能包含新的内容。全零的 sha1 意味着要获得真正的差异,需要直接查看工作目录中的对象,而不是进行对象间的差异。
Note
|
与其他同类命令一样,git diff-index 实际上并不查看文件内容。所以也许 kernel/sched.c 实际上并没有改变,只是你看了一下而已。无论哪种情况,都需要 git update-index 来使索引同步。
|
Note
|
你可以让各种文件同时显示为 “已更新” 和 “仍在工作目录中”。由于 “已更新” 的文件会显示有效的 sha1,而 “未与索引同步” 的文件则会显示特殊的全零 sha1,因此你总能分辨出哪个文件处于哪种状态。 |
GIT
属于 git[1] 文档