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:
- Strategic Branching:
- Create separate branches to preserve changes before removing them from primary branches, enabling future access and integration.
- Non-Destructive Reversal:
- Git's revert command creates new commits that undo changes while maintaining a complete history, unlike destructive operations like reset.
- Commit Isolation:
- Each commit can be individually managed, allowing precise control over which changes to keep, revert, or restore.
Why It Matters:
- Change Management Flexibility:
- Provides options to handle feature rollbacks without permanently losing work or disrupting team workflows.
- Error Recovery:
- Offers multiple paths to recover from mistakes in the commit or revert process.
- Release Management:
- Enables maintaining different feature sets across branches for different release cycles or environments.
How to Implement:
- Preserve Changes in Branch:
git checkout develop
git checkout -b feature/preserved-changes
- 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
- 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:
- Scenario:
- A team needs to remove recently merged features from the develop branch before a release, but wants to preserve them for later integration.
- Application:
# 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
- Result:
- The develop branch no longer contains the reverted features and is ready for release, while the complete changes remain preserved in the feature/future-release branch for later use.
Connections:
- Related Concepts:
- Git: The foundational version control system used in this workflow
- Branching Strategy: Approaches to organizing work across different Git branches
- Pull Requests: The mechanism by which changes were originally merged
- Broader Concepts:
- Release Management: Strategies for managing different versions of software
- Error Recovery: Techniques for recovering from mistakes in software development
- Journal:
- 2025-03-11: Had to use to do a release, but we weren't pushing some changes from the backend, so a feature had to be rollbacked
References:
- Primary Source:
- Git documentation on revert: https://git-scm.com/docs/git-revert
- Additional Resources:
- Git documentation on reset: https://git-scm.com/docs/git-reset
- Atlassian's guide on undoing changes: https://www.atlassian.com/git/tutorials/undoing-changes
Tags:
#git #version-control #revert #branch-management #software-development #error-recovery #rollback
Sources:
- From: Git