1

I have a local git, I made a commit (let's say my third commit), then I pushed to origin on a remote website.

I inadvertedly deleted a remote file, now I tried to push again with:

git push origin master

but it returns "Everything up-to-date"

I'm not sure I deleted other files, so how do I push to remote and "overwrite/add missing files" to last local commit.

Mr.Web
  • 6,992
  • 8
  • 51
  • 86
  • 1
    To clarify, I think you mean: you deleted a file in your local repo, then committed and pushed that change? And you want to revert that change? – Oliver Charlesworth Aug 23 '17 at 19:54
  • Nope, I pushed a commit to a remote, then I went in the remote and deleted FROM THE REMOTE, the local is the good one. – Mr.Web Aug 23 '17 at 19:54
  • 1
    Right ok. You have a non-bare repo on the remote, and you're also able to make changes to it via the (remote) filesystem. A force-push is probably the immediate fix. But you should probably also consider avoiding this setup (to avoid future mishaps in future). – Oliver Charlesworth Aug 23 '17 at 19:58
  • @OliverCharlesworth yes, tks! – Mr.Web Aug 23 '17 at 19:59

1 Answers1

1

git push origin <your_branch_name> --force

Even though this can solve your problem. Be careful though as this is a dangerous command.

See explanation here: How do I properly force a Git push?

dgolman
  • 196
  • 1
  • 13
  • I get this: error: src refspec maser does not match any. error: failed to push some refs to 'https://...' – Mr.Web Aug 23 '17 at 20:01
  • Seems you used `maser` instead of `master` – dgolman Aug 23 '17 at 20:03
  • Gosh you are right. Ok I fixed the typo and I still get "Everything up-to-date" and the missing files still missing – Mr.Web Aug 23 '17 at 20:05
  • To revert to a previous commit, ignoring any changes: `git reset --hard HEAD` Then try the force push. A last ditch effort, if you have a way to browse your files, on github or the github client, you can go to the `commits` tab and select a commit that you know has that file(s) and copy the contents over to a new file with same name in your local folder structure. – dgolman Aug 23 '17 at 20:07
  • For some reason `git reset --hard HEAD` and than `force` again does not work – Mr.Web Aug 23 '17 at 21:16
  • Can you try `git reset --hard` without the HEAD or to go back two commits and see if the file is there, `git reset HEAD~2` and make sure you run `git status` to see if the file is there. – dgolman Aug 24 '17 at 17:52