Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
# Checking out a specific commit causes detached HEAD: git checkout abc1234 # Git warns you: # HEAD is now at abc1234 Add login form # You are in 'detached HEAD' state. # You can look around and make experimental commits. # To save work done in detached HEAD — create a branch: git switch -c experimental-fix # Now your commits are safe on 'experimental-fix'. # To simply go back to your branch: git switch main # Accidental commits in detached HEAD? # Find them in the reflog (they stick around for ~30 days): git reflog # abc1234 HEAD@{0}: commit: My experimental change # def5678 HEAD@{1}: checkout: moving to abc1234 # Recover them by creating a branch at that commit: git branch recover-work abc1234 # Check where HEAD currently points: git log --oneline -1 git status # includes branch info
Result
Open