Extract authorship information from git repository

旧街凉风 提交于 2019-12-06 05:16:48

Overview

This is a fundamental misunderstanding of how Git works. Git does not commit patches or diffs; it commits trees and blobs, although packfiles certainly do some sort of deltification. Most of the commit history is calculated at run-time with some flavor of diff.

In other words, if your diff tools can do what you want, so can Git.

git-blame

The git-blame command won't do what you want, because the man page says (emphasis mine):

Annotates each line in the given file with information from the revision which last modified the line.

In other words, it's strictly line-oriented.

git-log

You can get close to what you want with git-log. For example:

# Show diffs with indifference to whitespace changes (e.g. indenting).
git log --patch --ignore-space-change

# Just ignore whitespace altogether.
git log --patch --ignore-all-space

# Show deletions with [- -] and additions with {+ +}.
git log --patch --word-diff=plain

# Custom diff format where ~ denotes newlines.
git log --patch --word-diff=porcelain

The porcelain format is intended for text processing, but it's very non-intuitive from a visual point of view. However, it is well-documented in man 1 git-diff for your programming pleasure.

The downside is that you will have to get your author information from the GIT_AUTHOR_NAME or GIT_COMMITTER_NAME associated with each commit, rather than having Git decorate it for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!