Lost all commits on forced push in github

I recently created a PR in a forked repo and added some commits. Later, I accidentally deleted a branch from git bash(was branchpresent in my forked repo). So I recreated a branch with the same name and in this, I tried to push new commits. But first, he rejected the commits, so I forcibly pressed commit, but that removed all previous commits from PR in github.

I don’t know what happened here. Is it also possible to return all lost commits?

+4
source share
2 answers

Before doing anything else, make a copy of your local repo.

git fsck --lost-found ( git fsck --dangling), ( SHA), git reflog, , .

:, , , "reflog" ( , reflog). , , git log --walk-reflogs --oneline --decorate, /.

/ ( / ), SHA , , ( ).

git log --graph --all --online --decorate ( ), , , , .

: git, , , " ", git, , .

:.

  • :

D:\software\sandpit\branchclonetest > git log --graph --oneline --all --decorate * 77d69c7 (HEAD -> fromNewBranch, origin/master, origin/fromNewBranch, origin/HEAD) new file * 88181c4 (origin/new_branch) new file * 175d1e1 (origin/test_branch_1) file for merge back to master * 5d5b028 file added in branch * 777984b yet another file * e0652e8 (origin/logoff) new test files added

  1. / .

D:\software\sandpit\branchclonetest > git fsck --lost-found Checking object directories: 100% (256/256), done. dangling commit 92cacfdb6265075b8fae5fd63b21219cf91ea0ec <-- WANT THIS ONE dangling commit 1ad608bd48fc8bdedd186d05cc486974d6890265 dangling commit 59622d01426d876aec3a7e9265d52648a66e13e5

  1. Checkout lost commit 92cacf...

D:\software\sandpit\branchclonetest > git checkout 92cacfdb6265075b8fae5fd63b21219cf91ea0ec Note: checking out '92cacfdb6265075b8fae5fd63b21219cf91ea0ec'... etc...

  1. , , :

D:\software\sandpit\branchclonetest > git log --graph --oneline --all --decorate * 77d69c7 (origin/master, origin/fromNewBranch, origin/HEAD, fromNewBranch) new file * 88181c4 (origin/new_branch) new file * 175d1e1 (origin/test_branch_1) file for merge back to master * 5d5b028 file added in branch * 777984b yet another file | * 92cacfd (HEAD) test <--- COMMIT FOUND HERE |/ * e0652e8 (origin/logoff) new test files added

. - git gc () , / ...

Update:

, - , , . "-walk-reflogs" "-g" git.

, , / - ( ).

, , git log --walk-reflogs , : git log --walk-reflogs --oneline --decorate ( , /, ).

+2

git reflog origin/name_of_your_branch . .

, , git push --force, . git push --force-with-lease .

, git fsck, .

+1

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


All Articles