Undocumented git-diff syntax
When trying "just to see it it would work", I noticed that the following syntax appears to do what it looks like it should do.
git diff v1.7.3-rc0:Documentation/RelNotes-1.7.3.txt v1.7.3:Documentation/RelNotes/1.7.3.txt
It is a useful thing, but I could not find described in the manpage. I have not dig this part of diff yet, and maybe someone would have already a description of it (does it simply allow to diff two arbitrary blobs ?). Is it here just by some magic side-effect ? :)
Another thought: if we can already compare arbitrary blobs, maybe it would not be so hard to
extend it to take arbitrary contents that are not stored as blobs yet ? (a quick hack would be to
insert an object for them, but that does not look too clean...). As a use-case, I'm often found generating diffs from within custom scripts, from contents derived from a git repo, but can't use all the bells and whistles (--color, --color-words, etc), just because I have to use plain diff; that makes the output of those scripts very inconsistent with native git commands.
Would there be any objections to moving into that direction ?
Signature · 1 line
Yann Dirson - Bertin Technologies
On Mon, Oct 11, 2010 at 3:03 PM, Yann Dirson <[email protected]> wrote:
[...]
Quoted 5 lines
Another thought: if we can already compare arbitrary blobs, maybe it would not be so hard to
extend it to take arbitrary contents that are not stored as blobs yet ? (a quick hack would be to
insert an object for them, but that does not look too clean...). As a use-case, I'm often found generating diffs from within custom scripts, from contents derived from a git repo, but can't use all the bells and whistles (--color, --color-words, etc), just because I have to use plain diff; that makes the output of those scripts very inconsistent with native git commands.
Are you talking about "git diff --no-index"?
HTH,
Santi
Quoted 13 lines · On Mon, 11 Oct 2010 15:59:18 +0200 Santi Béjar <[email protected]> wrote:
On Mon, Oct 11, 2010 at 3:03 PM, Yann Dirson <[email protected]> wrote:
[...]Quoted 10 lines
Another thought: if we can already compare arbitrary blobs, maybe it would not be so hard to extend it to take arbitrary contents that are not stored as blobs yet ? (a quick hack would be to insert an object for them, but that does not look too clean...). As a use-case, I'm often found generating diffs from within custom scripts, from contents derived from a git repo, but can't use all the bells and whistles (--color, --color-words, etc), just because I have to use plain diff; that makes the output of those scripts very inconsistent with native git commands.
Quoted 1 line
Are you talking about "git diff --no-index"?
Oh, right. That's what it takes to read only the 1st paragraph for each synopsis:
|If exactly two paths are given, and at least one is untracked, |compare the two files / directories. This behavior can be |forced by --no-index.
OTOH, that appears not to be 100% accurate (my tests would have shown me): although --no-index does give me the expected results when one or two of the files are untracked, I have to explicitely add it, which seem to contradict this part of the doc.
That said, this two-path construct would surely deserve its own synopsis.
To get back to my initial opuzzlement, maybe the behaviour I found is also a special case that sets --no-index ?
Signature · 1 line
Yann Dirson - Bertin Technologies
Quoted 4 lines · Yann Dirson
OTOH, that appears not to be 100% accurate (my tests would have shown me): although --no-index does give me the expected results when one or two of the files are untracked, I have to explicitely add it, which seem to contradict this part of the doc.
Yep, the doc is out of date. Luckily I had a series updating it rotting in my local tree.
Patch 5 gives --no-index its own prominent mention in the DESCRIPTION section. I suspect that is a bad idea --- too much to learn for new users --- and that the description should go under OPTIONS, but I ran out of time.
Maybe patches 1-4 can help?
Jonathan Nieder (5):
Documentation: gitrevisions is in section 7
Documentation: diff can compare blobs
Documentation: expand 'git diff' SEE ALSO section
Documentation: update "git diff --no-index" description
Documentation: expand diff --no-index description
Documentation/git-cat-file.txt | 2 +- Documentation/git-check-ref-format.txt | 2 +- Documentation/git-cherry-pick.txt | 2 +- Documentation/git-diff.txt | 36 ++++++++++++++++++++++++-------- Documentation/git-fast-import.txt | 2 +- Documentation/git-format-patch.txt | 2 +- Documentation/git-log.txt | 2 +- Documentation/git-push.txt | 2 +- Documentation/git-reflog.txt | 2 +- Documentation/git-revert.txt | 2 +- Documentation/git-show-branch.txt | 2 +- Documentation/git-show.txt | 2 +- Documentation/git.txt | 2 +- Documentation/gitcore-tutorial.txt | 2 +- Documentation/gitk.txt | 2 +- Documentation/user-manual.txt | 8 +++--- 16 files changed, 45 insertions(+), 27 deletions(-)
Signature · 1 line
1.7.2.3
PATCH 1/5 Documentation: gitrevisions is in section 7
Fix references to gitrevisions(1) in the manual pages and HTML documentation.
In practice, this will not matter much unless someone tries to use a hard copy of the git reference manual.
--- Documentation/git-cat-file.txt | 2 +- Documentation/git-check-ref-format.txt | 2 +- Documentation/git-cherry-pick.txt | 2 +- Documentation/git-diff.txt | 4 ++-- Documentation/git-fast-import.txt | 2 +- Documentation/git-format-patch.txt | 2 +- Documentation/git-log.txt | 2 +- Documentation/git-push.txt | 2 +- Documentation/git-reflog.txt | 2 +- Documentation/git-revert.txt | 2 +- Documentation/git-show-branch.txt | 2 +- Documentation/git-show.txt | 2 +- Documentation/git.txt | 2 +- Documentation/gitcore-tutorial.txt | 2 +- Documentation/gitk.txt | 2 +- Documentation/user-manual.txt | 8 ++++---- 16 files changed, 20 insertions(+), 20 deletions(-)
Documentation/git-cat-file.txt +1 -1
@@ -27,7 +27,7 @@ OPTIONS <object>:: The name of the object to show. For a more complete list of ways to spell object names, see - the "SPECIFYING REVISIONS" section in linkgit:gitrevisions[1]. + the "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. -t:: Instead of the content, show the object type identified by
Documentation/git-check-ref-format.txt +1 -1
@@ -49,7 +49,7 @@ git imposes the following rules on how references are named: These rules make it easy for shell script based tools to parse reference names, pathname expansion by the shell when a reference name is used unquoted (by mistake), and also avoids ambiguities in certain -reference name expressions (see linkgit:gitrevisions[1]): +reference name expressions (see linkgit:gitrevisions[7]): . A double-dot `..` is often used as in `ref1..ref2`, and in some contexts this notation means `{caret}ref1 ref2` (i.e. not in
Documentation/git-cherry-pick.txt +1 -1
@@ -21,7 +21,7 @@ OPTIONS <commit>...:: Commits to cherry-pick. For a more complete list of ways to spell commits, see - linkgit:gitrevisions[1]. + linkgit:gitrevisions[7]. Sets of commits can be passed but no traversal is done by default, as if the '--no-walk' option was specified, see linkgit:git-rev-list[1].
Documentation/git-diff.txt +2 -2
@@ -68,11 +68,11 @@ for the last two forms that use ".." notations, can be any <tree-ish>. For a more complete list of ways to spell <commit>, see -"SPECIFYING REVISIONS" section in linkgit:gitrevisions[1]. +"SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. However, "diff" is about comparing two _endpoints_, not ranges, and the range notations ("<commit>..<commit>" and "<commit>\...<commit>") do not mean a range as defined in the -"SPECIFYING RANGES" section in linkgit:gitrevisions[1]. +"SPECIFYING RANGES" section in linkgit:gitrevisions[7]. OPTIONS -------
Documentation/git-fast-import.txt +1 -1
@@ -439,7 +439,7 @@ Marks must be declared (via `mark`) before they can be used. * A complete 40 byte or abbreviated commit SHA-1 in hex. * Any valid Git SHA-1 expression that resolves to a commit. See - ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[1] for details. + ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[7] for details. The special case of restarting an incremental import from the current branch value should be written as:
Documentation/git-format-patch.txt +1 -1
@@ -39,7 +39,7 @@ There are two ways to specify which commits to operate on. that leads to the <since> to be output. 2. Generic <revision range> expression (see "SPECIFYING - REVISIONS" section in linkgit:gitrevisions[1]) means the + REVISIONS" section in linkgit:gitrevisions[7]) means the commits in the specified range. The first rule takes precedence in the case of a single <commit>. To
Documentation/git-log.txt +1 -1
@@ -31,7 +31,7 @@ OPTIONS either <since> or <until> is omitted, it defaults to `HEAD`, i.e. the tip of the current branch. For a more complete list of ways to spell <since> - and <until>, see linkgit:gitrevisions[1]. + and <until>, see linkgit:gitrevisions[7]. --follow:: Continue listing the history of a file beyond renames
Documentation/git-push.txt +1 -1
@@ -41,7 +41,7 @@ OPTIONS[[OPTIONS]] + The <src> is often the name of the branch you would want to push, but it can be any arbitrary "SHA-1 expression", such as `master~4` or -`HEAD` (see linkgit:gitrevisions[1]). +`HEAD` (see linkgit:gitrevisions[7]). + The <dst> tells which ref on the remote side is updated with this push. Arbitrary expressions cannot be used here, an actual ref must
Documentation/git-reflog.txt +1 -1
@@ -40,7 +40,7 @@ see linkgit:git-log[1]. The reflog is useful in various git commands, to specify the old value of a reference. For example, `HEAD@\{2\}` means "where HEAD used to be two moves ago", `master@\{one.week.ago\}` means "where master used to -point to one week ago", and so on. See linkgit:gitrevisions[1] for +point to one week ago", and so on. See linkgit:gitrevisions[7] for more details. To delete single entries from the reflog, use the subcommand "delete"
Documentation/git-revert.txt +1 -1
@@ -31,7 +31,7 @@ OPTIONS <commit>...:: Commits to revert. For a more complete list of ways to spell commit names, see - linkgit:gitrevisions[1]. + linkgit:gitrevisions[7]. Sets of commits can also be given but no traversal is done by default, see linkgit:git-rev-list[1] and its '--no-walk' option.
Documentation/git-show-branch.txt +1 -1
@@ -32,7 +32,7 @@ no <rev> nor <glob> is given on the command line. OPTIONS ------- <rev>:: - Arbitrary extended SHA1 expression (see linkgit:gitrevisions[1]) + Arbitrary extended SHA1 expression (see linkgit:gitrevisions[7]) that typically names a branch head or a tag. <glob>::
Documentation/git-show.txt +1 -1
@@ -36,7 +36,7 @@ OPTIONS <object>...:: The names of objects to show. For a more complete list of ways to spell object names, see - "SPECIFYING REVISIONS" section in linkgit:gitrevisions[1]. + "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. include::pretty-options.txt[]
Documentation/git.txt +1 -1
@@ -495,7 +495,7 @@ HEAD:: (i.e. the contents of `$GIT_DIR/refs/heads/<head>`). For a more complete list of ways to spell object names, see -"SPECIFYING REVISIONS" section in linkgit:gitrevisions[1]. +"SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. File/Directory Structure
Documentation/gitcore-tutorial.txt +1 -1
@@ -971,7 +971,7 @@ commits from the master branch. The string inside brackets before the commit log message is a short name you can use to name the commit. In the above example, 'master' and 'mybranch' are branch heads. 'master^' is the first parent of 'master' -branch head. Please see linkgit:gitrevisions[1] if you want to +branch head. Please see linkgit:gitrevisions[7] if you want to see more complex cases. [NOTE]
Documentation/gitk.txt +1 -1
@@ -69,7 +69,7 @@ frequently used options. the form "'<from>'..'<to>'" to show all revisions between '<from>' and back to '<to>'. Note, more advanced revision selection can be applied. For a more complete list of ways to spell object names, see - linkgit:gitrevisions[1]. + linkgit:gitrevisions[7]. <path>...::
Documentation/user-manual.txt +4 -4
@@ -397,7 +397,7 @@ is usually a shortcut for the HEAD branch in the repository "origin". For the complete list of paths which git checks for references, and the order it uses to decide which to choose when there are multiple references with the same shorthand name, see the "SPECIFYING -REVISIONS" section of linkgit:gitrevisions[1]. +REVISIONS" section of linkgit:gitrevisions[7]. [[Updating-a-repository-With-git-fetch]] Updating a repository with git fetch
@@ -568,7 +568,7 @@ We have seen several ways of naming commits already: - HEAD: refers to the head of the current branch There are many more; see the "SPECIFYING REVISIONS" section of the -linkgit:gitrevisions[1] man page for the complete list of ways to +linkgit:gitrevisions[7] man page for the complete list of ways to name revisions. Some examples: -------------------------------------------------
@@ -909,7 +909,7 @@ commits reachable from some head but not from any tag in the repository: $ gitk $( git show-ref --heads ) --not $( git show-ref --tags ) ------------------------------------------------- -(See linkgit:gitrevisions[1] for explanations of commit-selecting +(See linkgit:gitrevisions[7] for explanations of commit-selecting syntax such as `--not`.) [[making-a-release]]
@@ -1635,7 +1635,7 @@ you've checked out. The reflogs are kept by default for 30 days, after which they may be pruned. See linkgit:git-reflog[1] and linkgit:git-gc[1] to learn how to control this pruning, and see the "SPECIFYING REVISIONS" -section of linkgit:gitrevisions[1] for details. +section of linkgit:gitrevisions[7] for details. Note that the reflog history is very different from normal git history. While normal history is shared by every repository that works on the
Signature · 1 line
1.7.2.3
Re: [PATCH 1/5] Documentation: gitrevisions is in section 7
Heya,
Quoted 2 lines · Jonathan Nieder
Fix references to gitrevisions(1) in the manual pages and HTML documentation.
Nice catch. How did you find this? Have you check there aren't similar references that are wrong?
Signature · 3 lines
Cheers, Sverre Rabbelier
PATCH 2/4 Documentation: diff can compare blobs
In reply to Jonathan NiederMeanwhile, there is no plumbing command to compare two blobs. Strange.
--- Documentation/git-diff.txt | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
Documentation/git-diff.txt +3 -2
@@ -64,8 +64,9 @@ forced by --no-index. Just in case if you are doing something exotic, it should be noted that all of the <commit> in the above description, except -for the last two forms that use ".." notations, can be any -<tree-ish>. +in the last two forms that use ".." notations, can be any +<tree>. The third form ('git diff <commit> <commit>') can also +be used to compare two <blob> objects. For a more complete list of ways to spell <commit>, see "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
Signature · 1 line
1.7.2.3
PATCH 3/4 Documentation: expand 'git diff' SEE ALSO section
In reply to Jonathan NiederPoint in many directions in the hope of helping the reader find what is needed more quickly.
This commit also removes the summary attached to the SEE ALSO entry for difftool, to avoid making the SEE ALSO list too verbose. If the reader wants a summary of the commands referred to, she can always look to the top of the named pages or to the table of contents on the main git(1) page.
--- Documentation/git-diff.txt | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
Documentation/git-diff.txt +6 -2
@@ -160,8 +160,12 @@ rewrites (very expensive). SEE ALSO -------- -linkgit:git-difftool[1]:: - Show changes using common diff tools +diff(1), +linkgit:git-difftool[1], +linkgit:git-log[1], +linkgit:gitdiffcore[7], +linkgit:git-format-patch[1], +linkgit:git-apply[1] Author ------
Signature · 1 line
1.7.2.3
PATCH 4/4 Documentation: update "git diff --no-index" description
In reply to Jonathan NiederOriginally "git diff --no-index" triggered for untracked files within the tracked tree, but with v1.5.6-rc1~41 (Merge branch 'jc/diff-no-no-index, 2008-05-26) the command changed to only trigger when paths outside the tracked tree are mentioned.
--- Documentation/git-diff.txt | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
Documentation/git-diff.txt +3 -3
@@ -23,9 +23,9 @@ tree and the index file, or the index file and the working tree. further add to the index but you still haven't. You can stage these changes by using linkgit:git-add[1]. + -If exactly two paths are given, and at least one is untracked, -compare the two files / directories. This behavior can be -forced by --no-index. +If exactly two paths are given and at least one points outside +the current repository, 'git diff' will compare the two files / +directories. This behavior can be forced by --no-index. 'git diff' [--options] --cached [<commit>] [--] [<path>...]::
Signature · 1 line
1.7.2.3
[RFC/PATCH 5/4] Documentation: flesh out diff --no-index description
In reply to Jonathan NiederExplain what diff --no-index is used for in more detail.
--- Documentation/git-diff.txt | 21 +++++++++++++++++---- 1 files changed, 17 insertions(+), 4 deletions(-)
Documentation/git-diff.txt +17 -4
@@ -25,7 +25,7 @@ tree and the index file, or the index file and the working tree. + If exactly two paths are given and at least one points outside the current repository, 'git diff' will compare the two files / -directories. This behavior can be forced by --no-index. +directories (see --no-index below). 'git diff' [--options] --cached [<commit>] [--] [<path>...]::
@@ -62,11 +62,24 @@ directories. This behavior can be forced by --no-index. "git diff $(git-merge-base A B) B". You can omit any one of <commit>, which has the same effect as using HEAD instead. +'git diff' [--options] --no-index [--] <path> <path>:: + + In this form, 'git diff' will compare a pair of files or + directories that are not necessarily being managed by git. + The tracked content of files in the index and the object + database are ignored. ++ +In other words, this form allows 'git diff' to be used as a +traditional 'diff' command (plus the familiar extras like --check, +color, pagination, automatic use of -r, --stat/--name-status, +--pickaxe, --binary, copy/rename detection, -Oorderfile, and +--patience). + Just in case if you are doing something exotic, it should be noted that all of the <commit> in the above description, except -in the last two forms that use ".." notations, can be any -<tree>. The third form ('git diff <commit> <commit>') can also -be used to compare two <blob> objects. +in the two forms that use ".." notations, can be any <tree>. +The third form ('git diff <commit> <commit>') can also be used +to compare two <blob> objects. For a more complete list of ways to spell <commit>, see "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
Signature · 1 line
1.7.2.3
Re: [RFC/PATCH 5/4] Documentation: flesh out diff --no-index description
Documentation/git-diff.txt directories. This behavior can be forced by --no-index. · line 76
Quoted 12 lines · Jonathan Nieder
+'git diff' [--options] --no-index [--] <path> <path>::
Documentation/git-diff.txt +11
-0+ + In this form, 'git diff' will compare a pair of files or + directories that are not necessarily being managed by git. + The tracked content of files in the index and the object + database are ignored. ++ +In other words, this form allows 'git diff' to be used as a +traditional 'diff' command (plus the familiar extras like --check, +color, pagination, automatic use of -r, --stat/--name-status, +--pickaxe, --binary, copy/rename detection, -Oorderfile, and +--patience).
My initial knee-jerk reaction was "how would -C/-M/-O be useful when you can only give two paths?" Perhaps it would become easier to read if we phrased it like this?
This form allows 'git diff' to be used as a better 'diff' command, with extras like whitespace checks (--check), coloring (--color), wordwise diff (--color-words), pagination, diffstat (--stat), binary patch (--binary), alternative algorithm (e.g. --patience). In addition, when comparing two directories, rename detection (-M) may come in handy.
Note, by the way, that I didn't verify all the claims the above makes.
Quoted 7 lines · Jonathan Nieder
Quoted 4 lines · Yann Dirson
OTOH, that appears not to be 100% accurate (my tests would have shown me): although --no-index does give me the expected results when one or two of the files are untracked, I have to explicitely add it, which seem to contradict this part of the doc.
Quoted 7 lines
Yep, the doc is out of date. Luckily I had a series updating it rotting in my local tree.
Patch 5 gives --no-index its own prominent mention in the DESCRIPTION section. I suspect that is a bad idea --- too much to learn for new users --- and that the description should go under OPTIONS, but I ran out of time.
OTOH, not making it prominent does not help users to realize it is there. Keeping it last, or maybe in a "less frequently used" section looks fine to me - eg. the <commit>...<commit> form could join it into such a section
Quoted 1 line
Maybe patches 1-4 can help?
They make things much more clear, thanks.
So it looks like after this doc patch series, we're left with a couple of bugs:
* the "fatal: '../Makefile' is outside repository" seen by Santi
* the following which should probably complain that the files cannot be compared:
$ echo a>a;echo b>b $ git diff a b; echo $? 0
At least, I can't think of them as meaningful behaviours.
Best regards,
Signature · 1 line
Yann
Heya,
Quoted 4 lines · Jonathan Nieder
Patch 5 gives --no-index its own prominent mention in the DESCRIPTION section. I suspect that is a bad idea --- too much to learn for new users --- and that the description should go under OPTIONS, but I ran out of time.
Well, that answers my question in [1/5], *mutters at gmail's lack of a tree view*.
Signature · 3 lines
Cheers, Sverre Rabbelier
Quoted 21 lines · Yann Dirson
Quoted 13 lines · On Mon, 11 Oct 2010 15:59:18 +0200 Santi Béjar <[email protected]> wrote:
On Mon, Oct 11, 2010 at 3:03 PM, Yann Dirson <[email protected]> wrote:
[...]Quoted 10 lines
Another thought: if we can already compare arbitrary blobs, maybe it would not be so hard to extend it to take arbitrary contents that are not stored as blobs yet ? (a quick hack would be to insert an object for them, but that does not look too clean...). As a use-case, I'm often found generating diffs from within custom scripts, from contents derived from a git repo, but can't use all the bells and whistles (--color, --color-words, etc), just because I have to use plain diff; that makes the output of those scripts very inconsistent with native git commands.
Quoted 1 line
Are you talking about "git diff --no-index"?
Oh, right. That's what it takes to read only the 1st paragraph for each synopsis:
Quoted 8 lines
|If exactly two paths are given, and at least one is untracked, |compare the two files / directories. This behavior can be |forced by --no-index.OTOH, that appears not to be 100% accurate (my tests would have shown me): although --no-index does give me the expected results when one or two of the files are untracked, I have to explicitely add it, which seem to contradict this part of the doc.
You are right.
Additionally these two are not equivalent:
$ git diff Makefile ../Makefile fatal: '../Makefile' is outside repository
$ git diff Makefile $HOME/Makefile
(quoted diff) +0 -0
(with --no-index both work)
Quoted 3 lines
That said, this two-path construct would surely deserve its own synopsis.
+1
Santi
Quoted 2 lines · Yann Dirson
That said, this two-path construct would surely deserve its own synopsis.
Something like this? Just kidding...
SYNOPSIS
--------
+[verse]
'git diff' [<common diff options>] <commit>{0,2} [--] [<path>...]
+'git diff' [<common diff options>] <tree-ish> <tree-ish> [--] [<path>...] +'git diff' [<common diff options>] <blob-or-path> <blob-or-path>
Possibly that <tree-ish> can be also a <directory> (on filesystem).
You can e.g. use
git diff HEAD:git-gui/ 00e9de7^^
^^^^^^^^^^^^^ ~~~~~~~~~
\-- tree \-- commit (in subtree-merged history)
Signature · 3 lines
Jakub Narebski Poland ShadeHawk on #git