0

I'm a newbie with Git.
I have the following commits, viewable below: enter image description here


I would like to delete ONLY the first commit listed, so that the final result looks like this: enter image description here

Looking for a possible solution I tried:
Delete a specific commit knowing commit id
Delete commits from a branch in Git
But with little success, because I believe they don't fulfill what I have to do.

I don't understand why it is such a rare thing to find something that seems so trivial to me.
Memmo
  • 298
  • 3
  • 8
  • 31
  • 1
    The [second question you link to](https://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git) has the exact command you need as the first code block. – Joachim Sauer Jan 14 '20 at 12:48
  • 1
    `git reset --hard {id-of-commit}`, you can use this method, instead of writing full `id` you can simply specify the first 8 characters. – Ali Beyit Jan 14 '20 at 12:49
  • 3
    `But with little success` demonstrating what happened (edit the question showing the commands issued and the result) would at least make the question complete - it's not clear what problem you hit, or therefore why you do not think it's a duplicate of existing similar questions. – AD7six Jan 14 '20 at 12:54
  • 1
    Please do not add images of text to questions/answers - just put the text – AD7six Jan 14 '20 at 12:55
  • Does this answer your question? [Delete commits from a branch in Git](https://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git) – phd Jan 14 '20 at 15:01
  • As it was answered [here](https://stackoverflow.com/a/59734099/8275210), I should delete that commit not _go back to that commit_...! – Memmo Jan 15 '20 at 08:53

2 Answers2

1

You could try doing a hard reset here, but the best general answer would be to git revert that commit:

# from your branch
git revert 1ce826c3

The reason why reverting is generally preferable to a hard reset is that the former option is safe to use even if you already happened to have pushed your branch to the remote. In that case, if some other user did a pull in before you did a hard reset and force pushed, he could face serious problems. But, reverting just adds a new commit on top of the branch, and so is safe from this point of view.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

You can reset back to a commit prior to that

git reset --hard f765470b
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218