Today I Learned

Leverage git to quickly explore a new project

| 1 min read

Let’s assume you’re new to a project, want to quickly catch up with a team or from whatever other reason just want to grasp on what’s currently happening in it.

Other situation when this technique may be useful is when you feel you need to refactor or even rewrite some parts of the app and you’re wondering when to start. It may help you to choose where to start.

To achieve that we can leverage git combined with several simple commands in order to find places that were recently changing most frequently. And here it is:

git log --format=format: --name-only --since=6.month \
 | egrep -v '^$' \
 | egrep '\.swift$' \
 | egrep -v '\.generated.swift$' \
 | sort \
 | uniq -c \
 | sort -nr \
 | head -50

First we get all files that changed during last 6 months, filter out empty strings and filter in code files that you’re interested in. In some projects we also use files generated with Sourcery, that follow .generated.swift pattern and here we’re not interested in those.

Then we sort it, remove duplicates and precede each entry with a count, sort by most occurrences and leave only 50 most popular ones and that’s it! You can begin your browsing 🙂