Due to some bugs I couldn't solve, I've cloned my last GitHub repo commit. The app started working again. Then I pushed it back to the same repo, but the commits number got reseted to 1. Any way I can undo this?
Asked
Active
Viewed 36 times
1
-
Did you `git push --force`...? – Mateen Ulhaq Jan 23 '20 at 03:41
-
Perhaps post a link to your repo or add more details – Mateen Ulhaq Jan 23 '20 at 03:41
-
Also, check `git reflog` and `git fsck --unreachable` – Mateen Ulhaq Jan 23 '20 at 03:42
-
@Mateen Yes, I had to use git push --force. – Rony M. Jan 23 '20 at 03:43
-
1. Backup your `.git` folder. 2. Do the other two things I said. 3. "Don't use the `--force` Luke!" is valid advice for the future until you're 100% comfortable with git and know when it's OK to use. – Mateen Ulhaq Jan 23 '20 at 03:48
-
I know "--force" seemed just wrong, but that was the only way to push my changes since it wouldn't stop returning errors after errors. Thanks for the advice, though. So how do I back my git folder up? Been searching for a while and still have no clue... – Rony M. Jan 23 '20 at 04:29
-
1It's inside your project. `ls -a`. So something like `tar cf git_backup.tar .git`. – Mateen Ulhaq Jan 23 '20 at 04:51
1 Answers
1
To go back to the state before your git push --force, check the output of git reflog
Or look at the events in your GitHub repository
The idea is to reset locally to what you had before, then force push again, in order to reset the remote repository to its previous state.
Then you can clone again, make your fixes, add, commmit and do a regular push.

VonC
- 1,262,500
- 529
- 4,410
- 5,250