You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/development/advanced/status-vs-diff-index.md
+49-4Lines changed: 49 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Using `status` is friendly for everyday use as developer. The `diff-index` subco
13
13
14
14
Both `status` and `diff-index` can be used to see a list of paths and how they changed, using `from` and `to` as a pair of paths when moving or renaming a file.
15
15
16
-
Why use `diff-index` and not `status`? Using the former makes things more **predictable** when parsing output. Since the `from` file is always first, from left to right. While `status` has it on the right, which is hard because it is not always there. There might be other reasons I can't remember, maybe because there is a percentage similarity which shows up in `diff-index` for renames/moves.
16
+
Why use `diff-index` and not `status`? Using the former makes things more **predictable** when parsing output. Since the `from` file is always first, from left to right. While `status` has it on the right, which is hard because it is not always there. There might be other reasons I can't remember, maybe because there is a percentage similarity that shows up in `diff-index` for renames/moves.
17
17
18
18
19
19
## status
@@ -35,30 +35,75 @@ $ git status --short
35
35
M abc.txt
36
36
```
37
37
38
+
Sample output of multiple lines. Note use of spaces not tabs.
39
+
40
+
```console
41
+
$ git status --short
42
+
R LICENSE -> LIC
43
+
M docs/development/advanced/status-vs-diff-index.md
44
+
M src/test/git/parseOutput.test.ts
45
+
```
46
+
38
47
39
48
## diff-index
40
49
41
-
The less-known `git diff-index` subcommand. This is not so usable for day to to day use in the CLI but is great for scripts, or for a project such as this one.
50
+
The lesser-known `git diff-index` subcommand. This is not so usable for day to to day use in the CLI but is great for scripts, or a project such as this one.
42
51
43
52
```sh
44
53
$ git diff-index [FLAGS] PATH
45
54
```
46
55
47
56
> Compare a tree to the working tree or index
48
57
49
-
- Flags must appear before the path.
58
+
Notes:
59
+
60
+
- Output has tab separator between columns.
50
61
- Use `--cached` for _only_ staged changes. Note that the only way to pick up a new file or detect a move/rename pair properly with `diff-index` is to stage changes first and then use this flag.
62
+
- Use `--name-status` to show names and status of changed files.
63
+
- Use `-M` to detect renames (i.e. move or rename a file, stage both paths, then run the command with this flag to see it appear as `R100` or similar).
51
64
- The path is required - `HEAD` works fine.
52
65
53
66
e.g.
54
67
55
68
```console
56
69
$ git diff-index HEAD
57
-
$ :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M abc.txt
70
+
:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M abc.txt
71
+
```
72
+
73
+
```console
58
74
$ git diff-index --name-status HEAD
59
75
M abc.txt
60
76
```
61
77
78
+
Two files changed, with long paths:
79
+
80
+
```console
81
+
$ git diff-index --name-status HEAD
82
+
M docs/development/advanced/status-vs-diff-index.md
83
+
M src/test/git/parseOutput.test.ts
84
+
```
85
+
86
+
For a move or rename:
87
+
88
+
```console
89
+
$ mv LICENSE LIC
90
+
$ git add .
91
+
$ git diff-index --name-status -M HEAD
92
+
R100 LICENSE LIC
93
+
```
94
+
95
+
Even though you might be able to select the output in the console as spaces, it is actually tabs. Check with a tool that can show hidden characters.
0 commit comments