❔ Git - how to undo dumb stuff

im using visual studio 2022 and it gone like this : 1- i made a commit with wrong staged files (all of them) 2- i tried to revert commit 3- my changes to all files've gone and i'm left with aother unrevertable revert commit 4- i didnt push any commit yet how to remove last two commits and have my changes back?
5 Replies
Cracker
Cracker2y ago
there are few ways, you can create another branch from main and cherry-pick the commits you want to push to remote, by that you will skip that last two commit
TheHitchhiker
TheHitchhiker2y ago
thanks for the reply. but im not quite sure how to do that. can you provide more details?
Cracker
Cracker2y ago
okay, first do you have main/master branch that can create one brand new feature branch ? That branch will contain commits to push remote origin create one feature branch from your main branch then git cherry-pick -n commitId1 commitId2 commitId3 where commitId is the commit's Id from the branch which you have problem with, this will move specified commits to newly created branch (you should be in newly created branch, cherry-pick will move those commitIds to your current branch)
TheHitchhiker
TheHitchhiker2y ago
Thanks again, you helped a lot.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server