2.4History and undoing things

Reverting local changes, bringing back an old version, and reading what a commit actually did.

Section 4 of 7 in this chapter

Everything in this section is non-destructive. That is worth saying first, because the reason people lose work is usually that they were afraid to try the recovery.

Throwing away local changes

Right-click a changed file and choose Revert. Your local edits go away and the committed version comes back. This touches only your machine and only that file — nobody else sees anything.

Going back to an older version

This is the one people come to version control for, and it is three clicks.

  1. 1

    Open the file's history

    Click the file, or right-click and choose History. You get every version it has ever had, with the commit, the author, and the date behind each one.

  2. 2

    Pick a version

    Download it somewhere to inspect it first if you want to be sure, or restore it directly.

  3. 3

    Commit the restore

    A restore is an ordinary change to your working folder, so it becomes an ordinary commit. The version you rolled back *from* is still in history — you can always roll forward again.

  before:   v1 ── v2 ── v3 ── v4 ── v5 (current, broken)

  restore v3:

  after:    v1 ── v2 ── v3 ── v4 ── v5 ── v6 (= v3's bytes)
                          ▲                    ▲
                   what you wanted        what you now have
                                          v5 is still there
Figure 2-4. Restoring v3 writes a new version. Nothing is removed, so the mistake is still recoverable in both directions.

Reading a commit

Click any commit in the left panel to see exactly which files it touched and what happened to each. The same view exists in the dashboard under a project's Commits tab, which is the one to send to someone who does not have the desktop app open.

Was this helpful?

Back to top