git
keeps previous commits in the repo. I want to know how I can remove a specific commit (I have its ID) from my repo history further?
Asked
Active
Viewed 47 times
0

msrd0
- 7,816
- 9
- 47
- 82

AKSHAY SHINGOTE
- 407
- 1
- 8
- 22
-
3Possible duplicate of [Removing commit from middle of a branch](http://stackoverflow.com/questions/42518104/removing-commit-from-middle-of-a-branch) – Sajib Khan Mar 07 '17 at 05:49
-
Can anyone please explain me that ?? I didn't get that – AKSHAY SHINGOTE Mar 07 '17 at 09:03
1 Answers
0
As explained https://stackoverflow.com/a/42522493/1507546, you can use git rebase
# 06c8c77^ means the commit just before 06c8c77
git rebase -i 06c8c77^
# Your default editor configured for git will be opened with line similar to the following
In the first part you'll see many commits, the one you want to remove is at the bottom, you can compare the commit hash for that.
pick 91c0bd0 track one
....
pick 06c8c77 bla bla bla # the one to remove
To remove it, and as explain in the second part, all you need to do is to remove the line from the editor.
# ....
#
# If you remove a line here THAT COMMIT WILL BE LOST.
After that you should save and exit your editor. If this goes without error, you need to update the remote branch. If your branch's name is feature/my_branch
for instance, you need to do the following:
git push -f origin feature/my_branch # -f or --force to replace the remote feature/my_branch with the local one
N.B. This is safe as long as the branch is only used by a single developer when rebase
is used.