Is there any way to find the oldest line of code currently in the codebase? Out of curiosity, I'd like to be able to find the line or lines that have been unchanged for the longest time. I can imagine there is some way of running git blame
on each file in the repository and processing each of them, but I was wondering if there is a simpler option.
find oldest line of code in git repository?
Asked Answered
My solution to this: Using bash/git bash
git ls-files | xargs -L 1 git --no-pager blame | sed -E "s/.*([0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2})/\1/" | sort | head -n 1
This lists all files, blames each of them, removes everything up to the date, then sorts them alphabetically (which now is synonymous with chronologically) and displays the first (oldest) one.
You may wish to modify the format of git-blame
so it presents more nicely / shows filename + line / doesn't discard the information before the timestamp - if you were to put the date first, it would make "sed" redundant.
You can use git blam that will tell you who and when single line updated in a file and you can easily find oldest update line Here is command
git blame triple_welcome.rb
I'm talking about the oldest line in the entire repository, not just in a file. –
Kwon
© 2022 - 2024 — McMap. All rights reserved.
git diff
against the very first checkin, and work my way upwards (I'd be very suprised if nothing survived). That can be get confused by files being renamed, lines copied from a file to another one, and so on. – Text