Suppose you have the following scenario:
* 1bd2200 (HEAD, master) another commit * d258546 bad commit * 0f1efa9 3rd commit * bd8aa13 2nd commit * 34c4f95 1st commit
Where do you want to remove d258546 ie "bad commit".
Try performing an interactive reboot to remove it: git rebase -i 34c4f95
then your default editor will appear something like this:
pick bd8aa13 2nd commit pick 0f1efa9 3rd commit pick d258546 bad commit pick 1bd2200 another commit
just delete the commit line you want to remove and save + exit the editor:
pick bd8aa13 2nd commit pick 0f1efa9 3rd commit pick 1bd2200 another commit ...
git will continue removing this commit from your history, leaving something like this (remember the hash change in the descendant stream from the remote commit):
* 34fa994 (HEAD, master) another commit * 0f1efa9 3rd commit * bd8aa13 2nd commit * 34c4f95 1st commit
Now, since I believe that you have already pressed the bad fix on gitlab, you will need to cancel your graph in the repository (but with the -f option to prevent it from rejecting due to a non-quick state, i.e. git push -f <your remote> <your branch> )
Please be careful and make sure that no employee is already using a story that contains a "bad commit" in its branches.
Alternative option:
Instead of rewriting the story, you can simply create a new commit that negates the changes made by your bad commit, just enter git revert <your bad commit hash> . This option may not be as clean, but much safer (unless you are fully aware of what you are doing with interactive permutation).
Álvaro P.
source share