git/list[1] front-page[2] threads[3] people[4] search[5] about
 

CVS migration section to the tutorial.

From
Junio C Hamano <junkio@cox.net>
Date
Jun 2, 2005, 19:43 UTC
Message-ID
<7vll5s35pd.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.58.0505301253070.1876@ppc970.osdl.org>

I think a section to discuss "I am used to doing 'cvs xxx' to solve this problem, how do I do that in GIT" would be a good idea. Here is an example to talk about "cvs annotate".

------------
CVS annotate.

The core GIT itself does not do "cvs annotate" equivalent, but it has something much nicer.

Let's step back a bit and think about the reason why you would want to do "cvs annotate a-file.c" to begin with.

	- Are you really interested in _all_ the lines in that file?
	- Are you interested in lines _only_ in that file and do not
          care if the file was created by renaming from a different
          file?

You would use "cvs annotate" on a file when you have trouble with a function (or even a single "if" statement in that function) that happens to be defined in the file, which does not do what you want it to do. And you would want to find out why it was written in that way, because you are about to modify it to suit your needs, and at the same time you do not want to break its current callers. For that, you want to find out why the original author did things that way in the original context. That's why you want "cvs annotate". So your answer to the first question _should_ be "no". You do not care about the whole file, only a segment of it.

Also, in the original context, the same statement might have appeared at first in a different file and later the file was renamed to "a-file.c". Or the entire program may have constructs similar to the "if" statement you are having trouble with in different places, that you are still not aware of. So your answer to the second question _should_ be "no" as well.

As an example, assuming that you have this piece code that you are interested in in the HEAD version:

	if (frotz) {
		nitfol();
	}
you would use git-rev-list and git-diff-tree like this:
	$ git-rev-list HEAD |
	  git-diff-tree --stdin -v -p -S'if (frotz) {
		nitfol();
	}'

We have already talked about the "--stdin" form of git-diff-tree command that reads the list of commits and compares each commit with its parents. What the -S flag and its argument does is called "pickaxe", a tool for software archaeologists. When "pickaxe" is used, git-diff-tree command outputs differences between two commits only if one tree has the specified string in a file and the corresponding file in the other tree does not. The above example looks for a commit that has the "if" statement in it in a file, but its parent commit does not have it in the same shape in the corresponding file (or the other way around, where the parent has it and the commit does not), and the differences between them are shown, along with the commit message (thanks to the -v flag). It does not show anything for commits that do not touch this "if" statement.

To make things more interesting, you can give the -C flag to git-diff-tree, like this:

	$ git-rev-list HEAD |
	  git-diff-tree --stdin -v -p -C -S'if (frotz) {
		nitfol();
	}'

When the -C flag is used, file renames and copies are followed. So if the "if" statement in question happens to be in "a-file.c" in the current HEAD commit, even if the file was originally called "o-file.c" and then renamed in an earlier commit, or if the file was created by copying an existing "o-file.c" in an earlier commit, you will not lose track. If the "if" statement did not change across such rename or copy, then the commit that does rename or copy would not show in the output, and if the "if" statement was modified while the file was still called "o-file.c", it would find the commit that changed the statement when it was in "o-file.c".

[ BTW, the current versions of "git-diff-tree -C" is not eager enough
  to find copies, and it will miss the fact that a-file.c was created
  by copying o-file.c unless o-file.c was somehow changed in the same
  commit.]

To make things even more interesting, you can use the --pickaxe-all flag in addition to the -S flag. This causes the differences from all the files contained in those two commits, not just the differences between the files that contain this changed "if" statement:

	$ git-rev-list HEAD |
	  git-diff-tree --stdin -v -p -C -S'if (frotz) {
		nitfol();
	}' --pickaxe-all
Previous: Adam KropelinNext: Nicolas Pitre
Message 59 of 64 in “I want to release a "git-1.0"”
  1. Linus TorvaldsMay 30, 2005
  2. jeff millarMay 30, 2005
  3. Nicolas PitreMay 30, 2005
  4. Junio C HamanoJun 1, 2005
  5. Add -d flag to git-pull-* family.Junio C Hamano, Jun 1, 2005
  6. Nicolas PitreJun 1, 2005
  7. Junio C HamanoJun 1, 2005
  8. Junio C HamanoMay 30, 2005
  9. Junio C HamanoMay 30, 2005
  10. David GreavesMay 30, 2005
  11. Dave JonesMay 30, 2005
  12. Dmitry TorokhovMay 30, 2005
  13. Junio C HamanoMay 30, 2005
  14. Dmitry TorokhovMay 30, 2005
  15. Linus TorvaldsMay 31, 2005
  16. Ryan AndersonMay 30, 2005
  17. Linus TorvaldsMay 31, 2005
  18. Chris WedgwoodMay 30, 2005
  19. Chris WedgwoodMay 30, 2005
  20. Linus TorvaldsMay 31, 2005
  21. Junio C HamanoJun 1, 2005
  22. David LangJun 1, 2005
  23. Junio C HamanoJun 1, 2005
  24. David LangJun 1, 2005
  25. C. Scott AnanianJun 1, 2005
  26. Nicolas PitreJun 2, 2005
  27. Brian O'MahoneyJun 2, 2005
  28. Junio C HamanoJun 1, 2005
  29. Petr BaudisMay 31, 2005
  30. Eric W. BiedermanMay 31, 2005
  31. Linus TorvaldsJun 1, 2005
  32. Junio C HamanoJun 1, 2005
  33. Fix -B "very-different" logic.Junio C Hamano, Jun 2, 2005
  34. Linus TorvaldsJun 3, 2005
  35. Junio C HamanoJun 3, 2005
  36. 0/4 Fix -B "very-different" logic.Junio C Hamano, Jun 3, 2005
  37. 1/4 Tweak count-delta interfaceJunio C Hamano, Jun 3, 2005
  38. 2/4 diff: Fix docs and add -O to diff-helper.Junio C Hamano, Jun 3, 2005
  39. 3/4 diff: Clean up diff_scoreopt_parse().Junio C Hamano, Jun 3, 2005
  40. 4/4 diff: Update -B heuristics.Junio C Hamano, Jun 3, 2005
  41. Junio C HamanoJun 1, 2005
  42. Daniel BarkalowJun 1, 2005
  43. Junio C HamanoJun 1, 2005
  44. Petr BaudisJun 3, 2005
  45. Daniel BarkalowJun 3, 2005
  46. Eric W. BiedermanJun 2, 2005
  47. Kay SieversJun 2, 2005
  48. Linus TorvaldsJun 2, 2005
  49. several typos in tutorialAlexey Nezhdanov, Jun 2, 2005
  50. Vincent HanquezJun 2, 2005
  51. Alexey NezhdanovJun 2, 2005
  52. Vincent HanquezJun 2, 2005
  53. Alexey NezhdanovJun 2, 2005
  54. Alexey NezhdanovJun 2, 2005
  55. Adam KropelinJun 2, 2005
  56. Linus TorvaldsJun 3, 2005
  57. Linus TorvaldsJun 3, 2005
  58. Adam KropelinJun 3, 2005
  59. CVS migration section to the tutorial.Junio C Hamano, Jun 2, 2005
  60. Nicolas PitreJun 2, 2005
  61. Nicolas PitreJun 2, 2005
  62. Junio C HamanoJun 2, 2005
  63. Linus TorvaldsJun 2, 2005
  64. Junio C HamanoJun 2, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.