Chapter 27 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.
27.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.
Once you’re viewing the history, notice three ways to access more info for each commit:
- 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.
- Click on the abbreviated SHA-1 itself in order to the view the diff associated with the commit.
- Click on the double angle brackets
<>to browse the state of the entire repo at that point in history.
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.
27.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.
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
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.
Search is always available in the upper-righthand corner of GitHub.
Once you enter some text in the search box, a dropdown provides the choice to search in the current repo (the default) or all of GitHub. GitHub searches the contents of files (described as “Code”), commit messages, and issues. Take advantage of the search hits across these different domains. Again, this is a powerful way to zoom in on specific lines of code, revisit an interesting time in project history, or re-discover a conversation thread.
27.4.1 Issue search
If you want to search issues specifically, the search box on any repo’s Issues page is prepopulated with the filters