Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to annotate "git diff"?

I'm trying to summarize the difference between an "old" and "new" state of the codebase.

  • I could just do "git log", but sadly the commit messages aren't always sufficient.
  • I could do "git diff", but I'd like to see some explanations to the differences I'm seeing, or at least commit hashes to save for later
  • I could do a "git diff --stat" and then "git annotate" for the files that changed, but I don't see how to ask annotate to only show changes since a particular commit.

Ideally, I'd like to get the output of "git diff" where all the "+" and "-" lines would be annotated with information about commits which last introduced these changes; ideally, in a git pretty format (e.g. hash, author and date).

How can this be achieved?

like image 913
jkff Avatar asked Nov 06 '12 13:11

jkff


People also ask

How do I see git diff?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.

What is annotate with git blame?

From git-blame: Annotates each line in the given file with information from the revision which last modified the line. Optionally, start annotating from the given revision. When specified one or more times, -L restricts annotation to the requested lines.

How do I see diff before commit?

The diff can be done with git diff (followed by the filename or nothing if you want to see the diff of all modified files). But if you already did something like git add * , you have to undo with git restore --staged . first.


1 Answers

You could write a small script which does something like

git blame before > before git blame after > after diff -u before after 

:)

See man 1 git re: GIT_EXTERNAL_DIFF.

like image 89
squadette Avatar answered Sep 19 '22 00:09

squadette