How to recover from git push -f?

I did git push -fon the branch and now have lost other people.

I could see in my github that another person’s work is shown (shown in action), but not in the remote branch (where I pushed my changes). Unfortunately, I do not have local repo synchronization with the remote control. Thus, I do not have the code of other people in my local. Is there a way that I can get to my local and restore?

+4
source share
3 answers

Before doing anything else, do these 3 steps - back up your local repo, tell the other guy to make a backup, and back up the remote repo, as it is now. Nothing unusual, just Ctrl + C, Ctrl + V. Do this throughout the project to create a backup copy of the working tree. If you do not have direct access to the remote server, you will need to git clone, although I would prefer a real copy of the directory.

, git push -f . , , , , . git pull -f, git reflog .

Github, fooobar.com/questions/146945/.... -, API- Githubs, .

+4

GitHub REST-API

:

$ curl https://api.github.com/repos/<user>/<repo>/events

, , :

POST /repos/<user>/<repo>/git/refs
{
  "ref": "refs/heads/featureA",
  "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd"
}

curl:

$ curl -i -H "Accept: application/json" -H "Content-Type: application/json" \
    -X POST -d '{"ref":"refs/heads/featureA", \
                 "sha":"aa218f56b14c9653891f9e74264a383fa43fefbd"}' \
    https://api.github.com/repos/<user>/<repo>/git/refs
+3

I am not a git user, but a few days ago I crossed this post, I think this has a solution to your problem as well.

http://ohshitgit.com/

# undo the last commit, but leave the changes available
git reset HEAD~ --soft
git stash
# move to the correct branch
git checkout name-of-the-correct-branch
git stash pop
git add . # or add individual files
git commit -m "your message here"
# now your changes are on the correct branch
-6
source

Source: https://habr.com/ru/post/1654577/


All Articles