I've created a GitLab Private Repository after some changes I would like to go back to the first commit (And to delete the history of the other ones after it) and have it as my new master. I'm using git in cmd. Thx for your help :)
2 Answers
Those commands should do what you need:
git reset --hard <commit_sha>
git push --force origin master
Each commit has its SHA, which is its ID: Example: 06f052cd5fb363da851d18658b76a9512b84680c
if you want to come back to initial commit, just find that number of your commit.

- 3,770
- 1
- 24
- 39
-
Can you explain what is <commit_sha>? Edit: Thx, really helpful I'm gonna try it right now. – ItzSpex Oct 16 '18 at 21:35
-
updated answer with extra information. – madoxdev Oct 16 '18 at 21:38
-
"You are not allowed to force push code to a protected brach on this project" is the rejection reason. How can I fix it – ItzSpex Oct 16 '18 at 21:44
-
You should be able to unprotect it in the gitlab. – madoxdev Oct 16 '18 at 21:48
First you checkout the first commit you want to keep to the working directory.
git checkout <has of your commit>
After that you create a temporary empty branch.
git checkout --orphan tmpbranch
After you have createt this empty branch commit your files.
git add -A
git commit -m "<message of my first commit>"
Now you can delete the master branch.
git branch -d master
Now rename your tmpbranch to the master.
git branch -m master
Now push all to the server. If there are any errors remove the protection of the master branch in gitlab server.
git push -f origin master
I hope this helps.

- 390
- 1
- 8