Confirm that length of a git-maintained file remained non-decreasing

Calaf Source

For one project I maintain a file notes.txt in which I document my progress. The project, including notes.txt, is maintained under git.

Today I search for a string expecting many occurences, but I find only a handful. I'm concerned that in a bout of Emacs keystrokes, I mistyped a character that wiped out a chunk of the file, without even noticing. (Emacs does warn when a "big chunk" has been wiped out, but AFAIK there is no way to specify: warn me on decrease of the number of lines in a file.)

I have a few hundred commits. How can I retrieve the sequence of line numbers of notes.txt to confirm (visually or programmatically) that there wasn't a sudden reduction in a sequence that I'm expecting to be non-decreasing?



answered 6 months ago HRK44 #1

You can use git log --follow --stat -p -- filename, it will show all the commits and the diffs of the file you want.

Also this script might help you :

answered 6 months ago William Pursell #2

I had originally made this as merely a comment, since I was hoping someone would have a better solution. I'd love to see the cleaner solution!

In the meantime, you can use:

git log --format=%[email protected]%cd "$file" | while [email protected] read hash date; do 
    printf "%s: " "$date"
    git show "$hash:$file" | wc -l

comments powered by Disqus