>_ IzzyLab

Hands-on task

This task is step 6 of the course “Git: rewriting and rescuing history”

Pull a value out of history

medium~5 min

In /root/repo the file version.txt changed several times, and some commits are tagged. version.txt no longer holds the value it had at tag v1.

Extract from history the contents of version.txt as of tag v1 and write them to the file /root/answer.txt (exactly that historical value, unchanged). You should not touch the working file version.txt.

What you'll practise:
  • git show
  • revisions
  • tags
  • rev:path syntax
  • file history

Topic breakdown

You can retrieve a file's contents at any past revision without switching your working tree to it: git understands a reference of the form <revision>:<path>, where the revision is a hash, a branch, or a tag. git show with such an argument outputs the file exactly as it was in that snapshot. This captures the key idea that every commit is an immutable snapshot of the tree, which you can always address by name without touching the current state.

What's checked

  1. answer.txt holds the historical value of version.txt

What it looks like