Home > Software design >  I jumped branches and now my code is lost, how to restore it
I jumped branches and now my code is lost, how to restore it

Time:01-19

First of all would say I am new to using repos. Being said that I did some changes and did a commit today but for some reason it was not going through some file was too big etc. So I jumped to main branch and everything is lost.

I don't see my code any where even though I moved back to

9d85487f835d73c02a818772ed58d73c9d53352c

But everything seems gone ...Please help

enter image description here

** UPDATE*************

I do see old files but in one case the whole file is missing and in another see below:

enter image description here

****** FURTHER UPDATE****************

 PS E:\Websites\sampleSite\src\presentation> git status
Refresh index: 100% (24853/24853), done.
On branch 9d85487f835d73c02a818772ed58d73c9d53352c
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   Nop.Web/Controllers/HomeController.cs
        modified:   Nop.Web/Plugins/DiscountRules.CustomerRoles/Nop.Plugin.DiscountRules.CustomerRoles.dll
        modified:   Nop.Web/Plugins/DiscountRules.CustomerRoles/Nop.Plugin.DiscountRules.CustomerRoles.pdb
        modified:   Nop.Web/Plugins/ExchangeRate.EcbExchange/Nop.Plugin.ExchangeRate.EcbExchange.dll
        modified:   Nop.Web/Plugins/ExchangeRate.EcbExchange/Nop.Plugin.ExchangeRate.EcbExchange.pdb
        modified:   Nop.Web/Plugins/ExternalAuth.Facebook/Nop.Plugin.ExternalAuth.Facebook.dll
        modified:   Nop.Web/Plugins/ExternalAuth.Facebook/Nop.Plugin.ExternalAuth.Facebook.pdb
        modified:   Nop.Web/Plugins/Misc.Sendinblue/Nop.Plugin.Misc.Sendinblue.dll
        modified:   Nop.Web/Plugins/Misc.Sendinblue/Nop.Plugin.Misc.Sendinblue.pdb
        modified:   Nop.Web/Plugins/Misc.WebApi.Frontend/Nop.Plugin.Misc.WebApi.Frontend.dll
        modified:   Nop.Web/Plugins/Misc.WebApi.Frontend/Nop.Plugin.Misc.WebApi.Frontend.pdb
        modified:   Nop.Web/Plugins/MultiFactorAuth.GoogleAuthenticator/Nop.Plugin.MultiFactorAuth.GoogleAuthenticator.dll
        modified:   Nop.Web/Plugins/MultiFactorAuth.GoogleAuthenticator/Nop.Plugin.MultiFactorAuth.GoogleAuthenticator.pdb
        modified:   Nop.Web/Plugins/Payments.CheckMoneyOrder/Nop.Plugin.Payments.CheckMoneyOrder.dll
        modified:   Nop.Web/Plugins/Payments.CheckMoneyOrder/Nop.Plugin.Payments.CheckMoneyOrder.pdb
        modified:   Nop.Web/Plugins/Payments.Manual/Nop.Plugin.Payments.Manual.dll
        modified:   Nop.Web/Plugins/Payments.Manual/Nop.Plugin.Payments.Manual.pdb
        modified:   Nop.Web/Plugins/Payments.PayPalCommerce/Nop.Plugin.Payments.PayPalCommerce.dll
        modified:   Nop.Web/Plugins/Payments.PayPalCommerce/Nop.Plugin.Payments.PayPalCommerce.pdb
        modified:   Nop.Web/Plugins/Payments.PayPalStandard/Nop.Plugin.Payments.PayPalStandard.dll
        modified:   Nop.Web/Plugins/Payments.PayPalStandard/Nop.Plugin.Payments.PayPalStandard.pdb
        modified:   Nop.Web/Plugins/Pickup.PickupInStore/Nop.Plugin.Pickup.PickupInStore.dll
        modified:   Nop.Web/Plugins/Pickup.PickupInStore/Nop.Plugin.Pickup.PickupInStore.pdb
        modified:   Nop.Web/Plugins/Shipping.EasyPost/Nop.Plugin.Shipping.EasyPost.dll
        modified:   Nop.Web/Plugins/Shipping.EasyPost/Nop.Plugin.Shipping.EasyPost.pdb
        modified:   Nop.Web/Plugins/Shipping.FixedByWeightByTotal/Nop.Plugin.Shipping.FixedByWeightByTotal.dll
        modified:   Nop.Web/Plugins/Shipping.FixedByWeightByTotal/Nop.Plugin.Shipping.FixedByWeightByTotal.pdb
        modified:   Nop.Web/Plugins/Shipping.UPS/Nop.Plugin.Shipping.UPS.dll
        modified:   Nop.Web/Plugins/Shipping.UPS/Nop.Plugin.Shipping.UPS.pdb
        modified:   Nop.Web/Plugins/Tax.Avalara/Nop.Plugin.Tax.Avalara.dll
        modified:   Nop.Web/Plugins/Tax.Avalara/Nop.Plugin.Tax.Avalara.pdb
        modified:   Nop.Web/Plugins/Tax.FixedOrByCountryStateZip/Nop.Plugin.Tax.FixedOrByCountryStateZip.dll
        modified:   Nop.Web/Plugins/Tax.FixedOrByCountryStateZip/Nop.Plugin.Tax.FixedOrByCountryStateZip.pdb
        modified:   Nop.Web/Plugins/Widgets.AccessiBe/Nop.Plugin.Widgets.AccessiBe.dll
        modified:   Nop.Web/Plugins/Widgets.AccessiBe/Nop.Plugin.Widgets.AccessiBe.pdb
        modified:   Nop.Web/Plugins/Widgets.FacebookPixel/Nop.Plugin.Widgets.FacebookPixel.dll
        modified:   Nop.Web/Plugins/Widgets.FacebookPixel/Nop.Plugin.Widgets.FacebookPixel.pdb
        modified:   Nop.Web/Plugins/Widgets.GoogleAnalytics/Nop.Plugin.Widgets.GoogleAnalytics.dll
        modified:   Nop.Web/Plugins/Widgets.GoogleAnalytics/Nop.Plugin.Widgets.GoogleAnalytics.pdb
        modified:   Nop.Web/Plugins/Widgets.NivoSlider/Nop.Plugin.Widgets.NivoSlider.dll
        modified:   Nop.Web/Plugins/Widgets.NivoSlider/Nop.Plugin.Widgets.NivoSlider.pdb
        modified:   Nop.Web/Plugins/Widgets.What3words/Nop.Plugin.Widgets.What3words.dll
        modified:   Nop.Web/Plugins/Widgets.What3words/Nop.Plugin.Widgets.What3words.pdb
        modified:   Nop.Web/obj/Debug/net6.0/Nop.Web.csproj.AssemblyReference.cache
        modified:   Nop.Web/obj/Debug/net6.0/project.razor.json

no changes added to commit (use "git add" and/or "git commit -a")

CodePudding user response:

It looks like you have a branch which has a name similar to the sha1 of one of your commits.

To confirm that : run git branch, and see if you see a branch named 9d85487f835d73c02a818772ed58d73c9d53352c in the output.

You could have reached that state if you ran git checkout -b 9d854... instead of git checkout 9d854... :

  • the first command (with -b) will create a branch named 9d854... pointing at the current commit (you were on the main branch at that time)
  • the second command (without -b) will switch to that commit, in a detached HEAD state

To fix that :

  • switch away from that branch: git switch main
  • delete that branch: git branch -d 9d85487f835d73c02a818772ed58d73c9d53352c (if you see a message stating "can't delete branch that isn't merged ...", use -D -- uppercase D -- to force deletion)

Things should now be back to normal.

  • you can run git log --graph --oneline 9d85487 to confirm that the history of commits is there,
  • if you want to integrate that commit to the main branch, merge that commit into main:
git switch main
git merge 9d85487
  • if you want to create your own feature branch, create a new branch named feature starting from that commit:
git switch -c feature 9d85487
  • Related