How to remove a commit in git that has no specified branch?
I have the following git repo structure:
a-b-c-d-.. [master] \ x
The commit x was accidentially done (can’t figure out how) and has no named branch. How can I delete this commit?
- Cordova install platforms/plugins from config.xml
- Git - update only files existing in current branch
- Pull single file on server
- Apply specific changeset from one TFS instance to another
- Ambiguous argument in git reset
- tortoisegit clone option is unavailable in right-click context menu
For detail, git log shows this (Translated back from german, sorry for any inconvieniances):
Author: ... Parents: 8444.. Branch: Follows up: Preceding: ...
The commit was not removable via
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 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.
git gc aggressively. May take time.
git gc --aggressive
git gc here.