Answer the question
In order to leave comments, you need to log in
Resetting an arbitrary git commit?
Can you please tell me if it is possible to delete an arbitrary commit from a branch (remove it so that it is not in the history)? that is, after some time of work there, I understand that I have a wrong commit, how can I remove it from the history?
Answer the question
In order to leave comments, you need to log in
git rebase -i %X%
(where %X%
= hash of the commit before the wrong one or @~N
, where N
= number of commits that have passed since the commit before the wrong one).
A text editor will open.
In it, replace pick
the wrong commit with drop
. Save and close. Git will clean it up. git push -f
.
Only:
1) NEVER do this if you are not the only one working with the repository
2) in the case of a specific github, even after this focus, the wrong commit will still be available by hash. It will be possible to completely clean it up only by dropping the turnip and recreating it (and filling in what happened after the rebase)
// while writing the answer and being distracted, ManWithBear already answered :)
Start a new branch and drag only the necessary commits there via cherry pick, you should not delete anything from the history.
here everyone rests on git rebase )
and for the sake of completeness, I will throw in git filter-branch
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question