Warm tip: This article is reproduced from serverfault.com, please click
git

git reset can't work when commited with force push

发布于 2020-11-28 05:31:20

I have forgotten to update my local repo with git pull and i commited to a file myfile.py and then pushed them with git push -f upstream master

Later i realised it and tried to reset to the commit id but after resetting found that it isn't showing the files which i have committed to the remote upstream (it's just the files in my local repo, with the commited myfile.py)

Anyway to reset to the point before it was commited with git push -f upstream master

Questioner
MissJuliaRobot
Viewed
0
Key 2020-11-28 16:17:16

Explanation

So first, the history of your local repository is different from your remote repository. When you forced push, your remote repository's history now matches with your local repository. What happens is, the changes in your remote repository before force pushing is already lost. So there aren't many ways to fix this.

Solution

However, you can ask a friend who has the latest history before you force pushed to force push his local repository. Then you can cherry-pick your commit in later.

Note

Force pushing is usually only used in branches that you work alone. Using it in branches that others are working with is extremely dangerous and you really need to know what you are doing if you really need to do so.

I think you accidentally post this twice. It's similar to this thread: git reset hard doesn't recover commits with force push