Remove commit on gitlab

How can I remove the commit I made on GitLab ? This commit I did is now not HEAD.

If I can’t delete it, can I change it?

When it was HEAD, I tried:

 git reset --soft HEAD git reset --soft HEAD^1 git revert HEAD git rebase -i HEAD git rebase -i HEAD~1 git reset --hard HEAD git reset --hard Id-Code 

I already tried to reinstall it, but it still remains on the branch. Now I just deleted it from HEAD, but it is still there.

Have another team?

+13
git gitlab
source share
3 answers

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 # Rebase 34c4f95..1bd2200 onto 34c4f95 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit log message # x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out 

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).

+22
source share

1.git reset --hard CommitId

2.git push -f master of the original

The 1st command will stop your head at commitid, and the 2nd command will delete all commits after this commit identifier in the main branch

Note. Remember to add -f to push, otherwise it will be rejected.

+16
source share

We had a similar problem, and this was not enough to remove only the commit and force click on GitLab.
It was still available in the GitLab interface using the URL:

 https://gitlab.example.com/<group>/<project>/commit/<commit hash> 

We had to remove the project from GitLab and recreate it in order to get rid of this commit in the GitLab user interface.

+2
source share

All Articles