Last active
February 8, 2024 06:23
-
-
Save SeLub/f3d61ae628d500e022f28822ad611127 to your computer and use it in GitHub Desktop.
Revisions
-
SeLub revised this gist
Feb 8, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Delete last commit from git ## First way -
SeLub revised this gist
Feb 8, 2024 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ # Remove last commit from git ## First way ```jsx git reset --hard HEAD~1 git push --force ``` ## Another way ``` git reset --hard "HEAD^" @@ -18,9 +18,9 @@ Both ways works fine. --- # Recover deleted commit to git ## Step 1. Find full SHA of deleted commit ```jsx git fsck --lost-found @@ -34,7 +34,7 @@ dangling commit 1b0b23f462cb4c560c3adfa821bcddd4e53e6a43 dangling blob b99c193caeccb77af13df8adb0358cee0b93eb82 ``` ## Step 2. Recover the dangling commit with rebase ```jsx git rebase 5601624a8926d4426ad42768bd0637fd82b70b80 -
SeLub renamed this gist
Feb 8, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
SeLub created this gist
Feb 8, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ ## Remove last commit from GitHub ### First way ```jsx git reset --hard HEAD~1 git push --force ``` ### Another way ``` git reset --hard "HEAD^" git push origin -f ``` Both ways works fine. --- ## Return removed commit to GitHub ### Step 1. Find full SHA of deleted commit ```jsx git fsck --lost-found Example output: Checking object directories: 100% (256/256), done. Checking objects: 100% (3/3), done. dangling commit 5601624a8926d4426ad42768bd0637fd82b70b80 dangling commit d5ee3e10a2c8b17b4e3cd7ee0562d6cdafacc5fa dangling commit 1b0b23f462cb4c560c3adfa821bcddd4e53e6a43 dangling blob b99c193caeccb77af13df8adb0358cee0b93eb82 ``` ### Step 2. Recover the dangling commit with rebase ```jsx git rebase 5601624a8926d4426ad42768bd0637fd82b70b80 git push ``` --- Deleted in this way commit still in **git reflog**. But garbage collector should remove typically in 30 days or so.