-1

I created a file in my GitHub repository, which was initially empty using the GitHub website. Now, I would like to revert the repository back to its original empty state, removing the file that was added and clearing the commit history.

I would appreciate any guidance or instructions.

I tried to use git reset -- HEAD^ but it didn't work.

Olesya
  • 11
  • 3
  • 2
    Why not just delete the directory and re-run `git init`? – Dai Jun 21 '23 at 11:18
  • I'm not sure which directory you're referring to. Currently, I don't have any local files; I only have the remote repository. I would prefer not to delete the repository and recreate it for two reasons. Firstly, I want to understand how to achieve the desired outcome without resorting to deletion. Secondly, I don't have sufficient permissions and I don't want to bother my boss just to avoid an extra commit. – Olesya Jun 21 '23 at 11:26
  • What do you mean by "remote repository"? How are you running `git reset` _remotely_? – Dai Jun 21 '23 at 11:27
  • Indeed, I cloned the repository in order to try the command, but it didn't yield the desired result. By mentioning the remote repository, I simply meant that I haven't made any commits locally on my cloned copy. – Olesya Jun 21 '23 at 11:36
  • 2
    I guess you could easily remove the repo in github and create it again.... but that's my _assumption_. – eftshift0 Jun 21 '23 at 11:39
  • I would just do an amend commit as your first commit followed by a force push :) – Kim Jun 21 '23 at 11:40

1 Answers1

0

Similar question answered here How to completely clear git repository, without deleting it
TL;DR:

git checkout <first commit hash>
git rm -r *
touch README
git add README
git commit --amend
git push -f
KirillDE
  • 16
  • 1
  • Thanks a lot, that really helped! I didn't actually need to checkout to the first commit since there was only one, but the rest of the solution worked like a charm. So I deleted the initial file, amended it with some extra changes, and then force-pushed everything to get things back on track. – Olesya Jun 22 '23 at 17:59