Help pleaseee ! My commit deleted the server's files!

Hi,

I’m a panicked student, and here is why :

Our teacher has given us access to his server to upload our work.

Yesterday I did a commit XX to add a single file on my teacher’s server, and once it was completed… all the other files that were present on the master’s branch of my teacher’s server were gone.

So I did a second commit YY to try to sort of undo my previous commit.
What I did is that I tried to download as much copies as possible of the deleted files on other websites, I pasted them in my git folder, and I pushed this git folder on my teacher’s server.

Today, someone did a new commit on the master branch.

If I want to cancel my two comits but not delete the commit this person did today… would it work if I write git revert --no-commit XX…HEAD
git commit

then git revert --no-commit YY…HEAD
git commit

I’d appreciate if you could help me…
Thank you very much

Git is a version control management and you can certainly revert any changes you’ve done.

You can revert specific commits you’d made that accidentally deleted files on the latest revisions of the repository.

Try performing the below (these can also be done on the command-line):

  • Visit your project on the GitLab UI
  • Click the history button
  • From the list that appears, locate the most recent (bad) commit you had authored, and click on it to visit its page
  • Review the change to assess if it needs to be undone, and click the Options > Revert button to try and revert it
  • Repeat for more such commits, moving from the most recent commit to the oldest, so the changes are reverted in the right (opposite) order