Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6391307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:39:21+00:00 2026-05-25T03:39:21+00:00

I have been working on some code, which I use git to manage. Earlier,

  • 0

I have been working on some code, which I use git to manage. Earlier, I used commit to save a version of my code that worked. I later decided to redo the code, since it needed some new features and was designed poorly. After I got it working, I did another git commit. After doing git log, I saw I was not on any branch. So, I did “git checkout master”. This brought be back to the version of my old code, with git log now showing my latest commit. This was A LOT of work, so I wanted to know if there was any way to undo what I did, and get back my latest code. Thanks in advance for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:39:22+00:00Added an answer on May 25, 2026 at 3:39 am

    Check the git reflog and find your commit.

    Safest thing is to create a branch at the “lost” commit, then check if everything is dandy using gitk or git log -p

    git branch recovery HEAD@{1} # use whatever commit you need
    git log -p recovery
    

    This new branch can then be merged, rebased on top of master, commits of it cherry-picked, etc. There are many possibilities in git to shoot yourself in the foot but also several more ways to re-attach that foot (possibly to your arms).

    If you haven’t done any new commits on master, you can simply merge the commit in question, which will be resolved as a fast-forward merge by git:

    git merge HEAD@{1} # use whatever commit you need
    

    If you don’t care about any new commits on master and you simply want to reset master branch to that lost commit, use git reset. To not lose any changes, stash changes to your working copy first (git stash save)

    git reset --keep HEAD@{1}
    

    The next time you discover that you aren’t on any branch, use git branch newbranch or git checkout -b newbranch

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on some legacy C++ code that uses variable length structures
I have some really complicated legacy code I've been working on that crashes when
I have been looking for a some working code for the last couple of
I have been working for some time on a library which performs numeric calculations.
I have been working on some games in Silverlight. However, the community and portal
I'm not a Notes programmer, however, for my sins, have been working on some
I have been working with Struts for some time, but for a project I
I have been working on a django app on my local computer for some
On a recent project I have been working on in C#/ASP.NET I have some
Recently I've been working on some embedded devices, where we have some structs and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.