Git remove commit from a pushed pull request

If ever you have to remove a commit from a pushed pull request, here is a simple way to do it. Bonus: it’s not adding a commit for the removal.

First be sure to be on the good branch

git checkout target-pull-request-branch

Then have a watch at the PRs commit tab and note the commits hash you want to remove (one or more)

Replace X by that number in the following command, which will make and interactive rebase for the X last commits

git rebase -i HEAD~X

You are now going to have an interactive text view, in which all the aimed commits are preceded by the word ‘pick’

Using the view like a text editor, replace the ‘pick’ word by ‘drop’ on the lines containing the targeted commit’s hashes .


Replaced pick with drop for commits 4aa3149 and 2031a79b:

Save and exit

In my case vim was the default text editor, so here you go escape colon w q

Push force the rebased repository

git push --force

This will remove the targeted commits and the only trace will be in the PR comments. The commit page will look like the rebased one, without the discarded commits nor a mention to them.

GitLab: WARNING: gl-sast-report.json: no matching files

When enabling SAST in a gitlab project you can have that kind of error at the tests part:

The yaml provided is not containing the needed part:

   name: sast
     - gl-sast-report.json
     sast: gl-sast-report.json
   when: always


GIT and BitBucket

Cloning a git repository from BitBucket can fail producing that kind of logs:

Clonage dans '.'...
remote: Counting objects: 7008, done.
remote: Compressing objects: 100% (5921/5921), done.
error: échec RPC ; curl 56 GnuTLS recv error (-110): La connexion TLS n’a pas été terminée correctement.
fetch-pack: unexpected disconnect while reading sideband packet
fatal: fin de fichier prématurée
fatal: échec de index-pack

Working solution was to force IPv4 with -4 option, like in the following example:

git clone -4 .