Knowledgebase

Undoing Changes in Git Print

  • softwareengineering, software, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Recovering from mistakes.

WHAT TO ESTABLISH FIRST

Whether the change has been shared.

WHY

That determines which options are safe.

WHAT TO USE FOR UNCOMMITTED CHANGES

Discarding them, or stashing them for later.

WHAT TO USE FOR A COMMIT NOT YET SHARED

Amending it, or resetting to an earlier point.

WHAT RESET DOES

Moves the branch pointer, optionally discarding changes.

WHAT TO BE CAREFUL WITH

Discarding changes permanently.

WHAT TO USE FOR A COMMIT ALREADY SHARED

A revert, which creates a new commit undoing it.

WHY

It does not alter history others have.

WHAT TO KNOW ABOUT RECOVERY

Git retains references to commits that appear lost, for a period.

WHAT THAT MEANS

Most accidental losses are recoverable.

WHERE TO LOOK

The record of where branch pointers have been.

WHAT TO DO BEFORE ANY RISKY OPERATION

Note the current commit identifier, or create a branch.

WHY

It gives you a way back.

WHAT TO NEVER DO ON A SHARED BRANCH

Force a push that discards others' work.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot