Word-by-word blame/annotate in version control?
Asked Answered
A

2

10

Is it possible to reconstruct a word-by-word history in version control? Ideally, I'd like to do is something like 1) I indicate the range of lines of interest, 2) have the program figure out the corresponding line numbers in previous versions, as code often moved up or down between versions (potentially limiting the range of versions, say since revision 19, or since a week ago), 3) print out a word-by-word history, either the versions that groups of words were last changed, or the authors by which groups of words were changed. So it's kind of like svn blame or git blame in a word-by-word level.

Failing that, are there tools that can do #1 and #2 above? That is, 1) I indicate the range of lines of interest, 2) have the program figure out the corresponding line numbers in previous versions, 3) the program would print out the history of these lines (when there were changes).

Either svn or git would be really helpful for me.

Atypical answered 20/7, 2013 at 2:16 Comment(3)
word by word! i don't think so, git tracks changes line by line. Are you trying to use git for writers? for programmers i don't think this level of blame is not required.Blesbok
Yes, I am trying to do this on a LaTex document, at least at the moment. It doesn't need to be something built-in to git though. I imagine a program external to git that can read git history can does this too.Atypical
@JeslyVarghese: Git tracks changes snapshot by snapshot. The line-based format is calculated on-the-fly, and it would also be possible to have a word-based format.Cesarean
V
2

I looked for something like this and ended up hacking up my own solution. You can find it here:

https://github.com/d33tah/wordblame

Basically, it creates a new repository directory in which all spaces are replaced by a newline and unique string signalling that there was a space. Then, "git blame" is executed and the result is reinterpreted.

Vo answered 2/12, 2015 at 14:30 Comment(1)
FYI I've ported your code to Python 3 since I got some encoding errors with Python 2: github.com/mdamien/wordblame/commit/…Infinitude
I
0

I've made a tool called git-word-blame to solve this exact problem:

# setup
> virtualenv -p python3 venv
> source venv/bin/activate
> pip install git-word-blame

# usage
> git word-blame your-file
> firefox /tmp/git-word-blame/word-blame-by-commit.html

I should look like this:

git word-blame screenshot

EDIT: Here's also another project from 2016 trying to character-based blame: https://cregit.linuxsources.org/

Infinitude answered 5/5, 2019 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.