N
N
NoName_02016-07-28 21:20:14
git
NoName_0, 2016-07-28 21:20:14

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

3 answer(s)
V
Vadim Misbakh-Soloviev, 2016-07-28
@NoName_0

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 pickthe 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 :)

D
Dmitry Zaitsev, 2016-07-29
@dim_s

Start a new branch and drag only the necessary commits there via cherry pick, you should not delete anything from the history.

A
Alexey Shumkin, 2016-08-04
@ashumkin

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 question

Ask a Question

731 491 924 answers to any question