1

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?

Calaf
  • 10,113
  • 15
  • 57
  • 120
  • If you are using an IDE such as Eclipse or IntelliJ, or a GUI tool, you can visually diff the head version of the file against an earlier commit. – Tim Biegeleisen Mar 13 '18 at 13:12
  • Perhaps you can find something [here](https://stackoverflow.com/q/47307978/5784831)? – Christoph Mar 13 '18 at 13:17
  • `git log --format=%H@%cd $file | while IFS=@ read hash date; do printf "%s: " "$date"; git show $hash:$file | wc -l; done ` – William Pursell Mar 13 '18 at 13:22
  • @WilliamPursell It works! I'd have preferred a solution that relies on either just git or on a real programming language, not bash (so I don't have to go googling for what IFS returns), but it works. – Calaf Mar 13 '18 at 13:38
  • @WilliamPursell Please add your comment as an answer so I can mark it as one. Bash is hardly my favorite programming language, but maybe there is no pure (or nearly so) git way to do this. – Calaf Mar 16 '18 at 16:05

2 Answers2

0

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 : https://stackoverflow.com/a/36723679/7991096

HRK44
  • 2,382
  • 2
  • 13
  • 30
  • The first statement "git log ..." prints the changes, not the line numbers. The second statement in the answer you linked has a pipeline, which becomes vacuous after grep ^commit (the regexp does not arise in the output). – Calaf Mar 13 '18 at 13:31
0

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=%H@%cd "$file" | while IFS=@ read hash date; do 
    printf "%s: " "$date"
    git show "$hash:$file" | wc -l
done 
William Pursell
  • 204,365
  • 48
  • 270
  • 300