Git Topics (9)Tap to view
    Git·Version Control·Topic 9 of 9

    Git Advanced Troubleshooting

    Clean up junk files, search for errors with bisect, and recover deleted commits via reflog.

    1. Advanced Troubleshooting and Cleanup

    1. git reflog -10

      What it doesDisplays the last 10 HEAD moves to restore commits or branches that were deleted or bypassed with reset

      When to use itEmergency moment when code is lost due to --hard reset or wrong rebase

      Examplegit reflog -10

    2. git branch recovery/lost-work <hash>

      What it doesCreates a new branch starting from any commit hash you found in the reflog

      When to use itto save and retrieve a lost work before it is deleted by the Garbage Collector

      Examplegit branch recovery/lost-work c7a1b2d

    3. git clean -nd

      What it doesDry run display of untracked files and folders that will be deleted without actually deleting

      When to use itA mandatory first step before any warehouse cleaning operation

      Examplegit clean -nd

    4. git clean -fd

      What it doesForcibly delete untracked files and empty folders from Working Tree (dangerous)

      When to use itto completely clean up construction waste and temporary experiments

      Examplegit clean -fd

    5. git clean -fdx

      What it doesDeletes all untracked files including ignored files in .gitignore

      When to use itto return the repository to a completely clean state as if it were a fresh clone

      Examplegit clean -fdx

    6. git bisect start

      What it doesStarts a binary search session to detect the exact commit that entered an error or regression

      When to use itWhen you discover a bug in your code and want to know exactly when and by whom it caused it

      Examplegit bisect start && git bisect bad && git bisect good v1.0.0

    7. git bisect reset

      What it doesEnds the bisect session and returns the HEAD to its original location before starting the scan

      When to use itAfter finding the commit causing the problem

      Examplegit bisect reset

    Offline · Reading cached copy