Lab: Git recovery, removal, and repository scale

Outcome

Use a disposable clone to restore and revert data safely, prove reflog is local recovery evidence, remove a fake secret from shared history with a coordinated rewrite, and choose a large-repository strategy from measured evidence.

Do

  1. In a disposable remote, make three commits. Use git restore to discard an uncommitted file change, git revert <commit> to create a shared-safe inverse commit, and git reflog to locate a locally lost commit. Recover it to a new branch; do not assume another clone has your reflog.
  2. Commit a clearly fake credential such as TRAINING_ONLY_DO_NOT_USE, push it, then treat it as compromised: revoke/rotate a real credential in a real incident before history work. Announce a maintenance window, stop writes, make a bare backup, use the organization-approved history-rewrite tool on the disposable remote, force-update with lease safeguards, and verify fresh clones no longer find the fake value. Require collaborators to reclone or reset as directed; delete the obsolete remote references only after verification.
  3. Measure a training repository with git count-objects -vH, clone time, checkout time, and largest paths. Put binaries in LFS where appropriate; set repository file-size/path policies. Evaluate Scalar only where supported and record before/after measurement. For shared components, compare a package/registry, a versioned separate repository, a submodule, or subtree rather than copying a giant shared folder into every repo.

Verify

Capture restore/revert/reflog results, fake-secret search before/after a fresh clone, rewrite communication/backup/force-update evidence, repository measurements, LFS/policy choice, and sharing decision. You should now understand: restore changes a worktree, revert preserves shared history, reflog is local, and history rewrite needs remote coordination plus credential response.

Break and fix

  1. Restore the wrong path in the disposable clone; use status/diff to identify and correct it before committing.
  2. Push a rewrite while a second clone adds a commit. Stop, preserve that work, communicate, repeat the rewrite from the agreed tip, and make the second clone reset/reclone.
  3. Add a large non-LFS test file; observe repository policy or clone impact, migrate the safe test artifact to LFS or remove it before it spreads.

Scenario practice

  1. Configure: Choose LFS, Scalar, repository policy, and a shared-component design from repo size, developer workflow, and release needs.
  2. Diagnose: A deleted commit is recoverable locally but not on a colleague’s clone. Inspect reflog, remote refs, branch reachability, and backup.
  3. Distinguish: Contrast restore, reset, revert, reflog recovery, history rewrite, credential revocation, LFS, and a package feed.

Clean up

Delete disposable remotes/clones/backups and fake credentials. Do not practise history rewriting or force pushing against production history.

Sources and re-audit

Re-audit when supported repository-scale tools, rewrite guidance, or remote policies change.

git · git-repository-scaling · secret-scanning · All labs