When undoing commits in Git, it's recommended to use 'git reset --keep' instead of 'git reset --hard' to avoid losing uncommitted changes. 'reset --hard' is highly destructive as it discards unsaved work, making recovery difficult. In contrast, 'reset --keep' preserves uncommitted changes and fails if it jeopardizes unsaved work. The post provides practical examples and suggests setting an alias for convenience.
4 Comments
Sort: