How to remove a commit in git that does not have the specified branch?

I have the following git repo structure:

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

Passing x was performed by accident (cannot understand how) and does not have a named branch. How to remove this commit?

For details, git log shows this (Translated from German, sorry for any inconvenience):

Author: ...
Parents: 8444..
Branch:
Follows up:
Preceding:

...

The end has not been deleted with git prune.

+3
source share
3 answers

If x is not in any branch history and is not checked, it will be automatically deleted with git sooner or later. You can see git help gcif you want to delete it right away. Setting gc.reflogExpireUnreachableto zero and then executing git gc --prune=nowis likely to do the trick.

git rebase, git commit --amend, ; git , , .

+4

git prune , , , .

+2

Run git gcaggressively. It may take some time.

git gc --aggressive

Read more about git gc here .

0
source

Source: https://habr.com/ru/post/1759179/


All Articles