1

I wanted to push a file to my GitHub account.

I did

git push origin master

and got an error

src refspec master does not match any.

I did

git push --force origin master

now all the other files in the repository are deleted

I want to reverse this step. How can I do that? Is it also possible to reverse changes through the web page interface in GitHub. Thanks.

user3490188
  • 499
  • 2
  • 6
  • 14
  • You probably got your first error message because you never committed anything to your new repo yet, is that correct? See [this answer](http://stackoverflow.com/a/7572252/456814). –  Apr 04 '14 at 20:09
  • We need more info about what previous steps and commands you used that led to your first error (did you `git init`, `git clone`). –  Apr 04 '14 at 20:20

1 Answers1

0

When something like that happens to me (very rarely) I can only think of git reflog which is a commit history of all your git commands.

So if you want to go back in time in a given git operation you can

$ git reflog
794e18b HEAD@{0}: commit (merge): Fixed conflicts
f9b382a HEAD@{1}: commit: Some minor errors on the file
1dc6496 HEAD@{2}: commit (amend): provisional tables for 
92f06d1 HEAD@{3}: commit (amend): provisional tables for 
a97a3a8 HEAD@{4}: commit: provisional tables for 
6ed9ebf HEAD@{5}: commit: @user changes.
8e79234 HEAD@{6}: commit: Changed the billboard and tables.sql
486acf6 HEAD@{7}: rebase -i (finish): returning to refs/heads/master
486acf6 HEAD@{8}: rebase -i (pick): Fixing some hal issues
e6d6e1a HEAD@{9}: rebase -i (pick): simple table definitions.

Now if I want to go back to let's say the a97a3a8 HEAD@{4}: commit: provisional tables for I just do

git reset --hard HEAD@{4}

Hope this saves your file :)

bitoiu
  • 6,893
  • 5
  • 38
  • 60
  • when i do git reflog it does not show the previous commits only the latest commit .. – user3490188 Apr 04 '14 at 17:05
  • I don't know why you don't have a reflog history, but this just means that you might want to stay a bit later today and re-write that file :( – bitoiu Apr 04 '14 at 17:07
  • He doesn't have a reflog history because he never even committed anything to his repo, probably. See [my comment](http://stackoverflow.com/questions/22868168/lost-some-files-in-git#comment34897635_22868168) to the question. –  Apr 04 '14 at 20:09