#atom

Subtitle:

Techniques for reverting changes while preserving work in Git repositories


Core Idea:

Git offers various approaches to undo or revert changes while still preserving the original work, allowing developers to maintain different versions of code across branches and recover from mistakes.


Key Principles:

  1. Strategic Branching:
    • Create separate branches to preserve changes before removing them from primary branches, enabling future access and integration.
  2. Non-Destructive Reversal:
    • Git's revert command creates new commits that undo changes while maintaining a complete history, unlike destructive operations like reset.
  3. Commit Isolation:
    • Each commit can be individually managed, allowing precise control over which changes to keep, revert, or restore.

Why It Matters:


How to Implement:

  1. Preserve Changes in Branch:
git checkout develop
git checkout -b feature/preserved-changes
  1. Revert Commits from Main Branch:
git checkout develop
git revert <commit-hash-of-PR-1>
git revert <commit-hash-of-PR-2>
git push origin develop 
  1. Undo Mistaken Reverts:
    For unpushed reverts:
git reset --hard HEAD~1  
# Undo most recent revert

For pushed reverts:

git revert <hash-of-the-revert-commit>
git push origin develop

Example:

# Create a preservation branch
git checkout develop
git checkout -b feature/future-release

# Revert the merged PRs in develop
git checkout develop
git revert a1b2c3d4  # First PR commit hash
git revert e5f6g7h8  # Second PR commit hash
git push origin develop

Connections:


References:

  1. Primary Source:
  2. Additional Resources:

Tags:

#git #version-control #revert #branch-management #software-development #error-recovery #rollback


Sources: