-2

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

madoxdev
  • 3,770
  • 1
  • 24
  • 39
ItzSpex
  • 1
  • 1
  • 2

2 Answers2

2

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.

madoxdev
  • 3,770
  • 1
  • 24
  • 39
0

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.

sweting
  • 390
  • 1
  • 8