0

l couldn't find a way to delete a commit and remove it from Github history and git log by specific commit id

KingAziz
  • 7
  • 2
  • 4
  • You only want to remove a specific git commit? What is with `git log`? – SwissCodeMen Mar 02 '22 at 22:17
  • @SwissCodeMen l made some useless commits l want them removed from git log where its track commits and in Github history l want to remove them like they were never committed – KingAziz Mar 02 '22 at 22:18
  • 1
    Look at this [question](https://stackoverflow.com/questions/2938301/remove-specific-commit) – SwissCodeMen Mar 02 '22 at 22:22
  • @SwissCodeMen yes already did l couldn't find what I'm looking for is there something l missed ? – KingAziz Mar 02 '22 at 22:30
  • 1
    In Git, you can't "remove" a commit without re-writing all the commits that came after it. One way to rewrite commits is called `rebase`. The question @SwissCodeMen linked to has multiple ways to do it. The one you want is probably `git rebase -i ...` . The `-i` means "interactive" so that you tell it which commits to remove, by literally deleting the line, or changing "pick" to "drop" or "d". – TTT Mar 02 '22 at 22:39
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 03 '22 at 06:13

1 Answers1

3

Remove the specific commit-id:

git rebase --onto commit-id^ commit-id

and then forcibly push to GitHub:

git push --force-with-lease

Read git-rebase documentation and git-push documentation for more information.

lzhh
  • 852
  • 7
  • 16