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
- In a disposable remote, make three commits. Use
git restoreto discard an uncommitted file change,git revert <commit>to create a shared-safe inverse commit, andgit reflogto locate a locally lost commit. Recover it to a new branch; do not assume another clone has your reflog. - 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. - 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
- Restore the wrong path in the disposable clone; use status/diff to identify and correct it before committing.
- 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.
- 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
- Configure: Choose LFS, Scalar, repository policy, and a shared-component design from repo size, developer workflow, and release needs.
- Diagnose: A deleted commit is recoverable locally but not on a colleague’s clone. Inspect reflog, remote refs, branch reachability, and backup.
- 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
- Manage large files in Azure Repos, checked 2026-08-22.
- Git reflog, checked 2026-08-22.
- Removing sensitive data from a repository, checked 2026-08-22.
Re-audit when supported repository-scale tools, rewrite guidance, or remote policies change.