30 Time travel: See the past

Sometimes you just need to see various files in your project as they were at some significant moment in the past. Examples:

  • “I liked the color scheme of this plot better in last week’s draft”. “What’s up with that new funky outlier in figure 2?”
    • Here you’ll want to visit scripts and source data as they were the last time you generated visualizations to share with this colleague.
  • “The build has been failing on Windows for two weeks.”
    • Here you’ll want to inspect package source at the “last known good” version and scrutinize subsequent commits.

All projects move through various states that you regard as “good” vs. “bad” or something in between. It can be useful to explore the past, when trying to get into a “good” state.

30.2 Browse commit history and specific commits

From your repo’s landing page, access commit history by clicking on “xyz commits”. This is like using git log locally, but much more rewarding. If you have a good local Git client, it probably also provides a graphical overview of history.

Link to commit listing on GitHub.

Figure 30.1: Link to commit listing on GitHub.

Once you’re viewing the history, notice three ways to access more info for each commit:

  1. The clipboard icon copies the SHA-1 of the commit. This can be handy if you need to refer to this commit elsewhere, e.g. in an issue thread or a commit message or in a Git command you’re forming for local execution.
  2. Click on the abbreviated SHA-1 itself in order to the view the diff associated with the commit.
  3. Click on the double angle brackets <> to browse the state of the entire repo at that point in history.
Example of a commit listing on GitHub.

Figure 30.2: Example of a commit listing on GitHub.

Back out of any drilled down view by clicking on YOU/REPO to return to your repo’s landing page. This brings you back to the present state and top-level of your repo.

30.3 File driven inquiries

What if you’re interested in how a specific file came to be the way it is? First navigate to the file, then notice “Blame” and “History” in the upper right.

Visiting a specific file on GitHub.

Figure 30.3: Visiting a specific file on GitHub.

30.3.1 Blame

The “blame” view of a file is related to what git blame does on the command line. It reveals who last touched each line of the file, how long ago, and the associated commit message. Click on the commit message to visit that commit. Or click the “stacked rectangles” icon to move further back in time, but staying in blame view. This is handy when doing forensics on a specific and small set of lines.

add a screenshot (and update that above) but first pick a better example than Happy Git, i.e. one with more contributors / more interesting history

30.3.2 History

The “history” view for a file is very much like the overall commit history described above, except it only includes commits that affect the file of interest. This can be handy when your inquiry is rather diffuse and you’re trying to digest the general story arc for a file.