Story Details

  • Find the oldest line in your repo

    Posted: 2025-01-27 02:51:42

    Milo Fultz's blog post details a method for finding the oldest lines of code in a Git repository. The approach leverages git blame combined with awk and sort to extract commit dates and line numbers. By sorting the output based on these dates, the script identifies and displays the oldest surviving lines, effectively pinpointing code that has remained unchanged since its initial introduction. This technique can be useful for understanding the evolution of a codebase, identifying potential legacy code, or simply satisfying curiosity about a project's history.

    Summary of Comments ( 22 )
    https://news.ycombinator.com/item?id=42836900

    Hacker News users discussed various methods and tools for finding the oldest lines of code in a repository, expanding on the article's git blame approach. Several commenters suggested using git log -L for more precise tracking of specific lines or functions, highlighting its ability to handle code moves and rewrites. The practicality of such analysis was debated, with some arguing its usefulness for understanding legacy code and identifying potential refactoring targets, while others questioned its value beyond curiosity. Alternatives like git-quick-stats and commercial tools like CodeScene were also mentioned for broader code history analysis, including visualizing code churn and developer contributions over time. The potential pitfalls of relying solely on line age were also brought up, emphasizing the importance of considering code quality and functionality regardless of its age.