GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — git-learning-log/undo-practice.md at master · VortexSentinel/git-learning-log

Expand file tree

/

undo-practice.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
45 lines (32 loc) · 1.7 KB
/

undo-practice.md

Copy path

File metadata and controls

45 lines (32 loc) · 1.7 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Git Toolkit

This file documents the Git undo and recovery tools I've learned.

Reset

  • git reset --soft HEAD~1: undo last commit, keep changes staged
  • git reset --mixed HEAD~1: undo last commit, keep changes in working directory (default)
  • git reset --hard HEAD~1: undo last commit and discard all changes (dangerous!)
  • Only safely use reset on commits that haven't been pushed

Revert

  • git revert HEAD: create a new commit that undoes the last commit
  • git revert is safe for shared/pushed branches because it doesn't rewrite history
  • The original commit stays in the log, plus a new "undo" commit is added

Reflog

  • git reflog: shows everywhere HEAD has pointed (commits, resets, checkouts)
  • Reflog entries last about 90 days before being garbage collected
  • To recover: find the SHA in reflog, then git branch

Cherry-pick

  • git cherry-pick : apply a specific commit to the current branch
  • Creates a new commit with the same changes but a different SHA
  • Use for hotfixes: fix on feature branch, cherry-pick to main

Bisect

  • git bisect start: begin a binary search session
  • git bisect bad: mark current commit as containing the bug
  • git bisect good : mark a known-good commit
  • Git checks out middle commits; you test and mark good/bad
  • git bisect reset: end the session and return to original HEAD

Tags

  • git tag -a v1.0 -m "message": create an annotated tag (stores tagger, date, message)
  • git tag v1.0: create a lightweight tag (just a pointer, no metadata)
  • git push origin v1.0: push a specific tag to remote
  • git push --tags: push all tags
  • Annotated tags are for releases; lightweight tags are for private/temporary labels
  • CI/CD pipelines often trigger on new tags
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.