How to remove a commit in git that has no specified branch?

I have the following git repo structure:

a-b-c-d-.. [master]

The commit x was accidentially done (can’t figure out how) and has no named branch. How can I delete this commit?

For detail, git log shows this (Translated back from german, sorry for any inconvieniances):

Author: ...
Parents: 8444..
Follows up:


The commit was not removable via git prune.

  • Stuck in either a headless state or at the start of the branch in git
  • Is there a better way of writing a git pre-commit hook to check any php file in a commit for parse errors?
  • Determining if a file modified between 2 commits in git
  • Github API for Python : PyGithub - get a list of all commits for a particular repository
  • Renaming a remote (bare) repository with git
  • How to fork a branch in Git?
  • How do I prevent SVN from caching credentials for a single repository?
  • GIT Can't push after pull other branch
  • 3 Solutions collect form web for “How to remove a commit in git that has no specified branch?”

    If x isn’t in any branch’s history, and isn’t checked out, it will automatically be removed by git sooner or later. You can look at git help gc if you want to remove it right away. Setting gc.reflogExpireUnreachable to zero and then doing git gc --prune=now will probably do the trick.

    git rebase, git commit --amend, and other such commands leave these kind of leftovers all the time; git is usually decent enough at dealing with them that you don’t have to worry about it.

    git prune will do what you want, but it will delete all unreachable objects, not just a specific one.

    Run git gc aggressively. May take time.

    git gc --aggressive

    More on git gc here.

    Git Baby is a git and github fan, let's start git clone.