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 8003025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:32:35+00:00 2026-06-04T16:32:35+00:00

I have a question that’s similar to How to undo 'git add' before commit?

  • 0

I have a question that’s similar to How to undo 'git add' before commit?, but with an important difference:

background:

I’m running some code that’s generating files which I’ll add to my repository when complete. The code that’s generating the files is new code, and in flux, so I’m sometimes running it more than once, with changes.

Along the way, I’m adding the generated files to the index, so they’ll be ready for one big commit at the end. This also allows me to check to see if my changes to the code create changes in the output, and if so, what those changes are. But… I accidentally ran another git add on a file that had showed up both in the Changes to be committed section (as a new file) and the Changes not staged for commit section (as modified). I meant to run a git diff on it, but I slipped and re-added it, so now I don’t have a way to diff it (that I know of), so…

the question:

Is there a way to undo just the last staging operation, such that a previously-added version will still/again be in the index, and the modified file will again be in my working tree, so that I can diff it?

None of this is committed or anything, as the goal is to commit it all together when I’m done with this little round of development. I just really like that git can normally show me changes to new files, before they’re committed… but… I missed a chance at that, and am now wondering if there’s a way to get it back. ?

The things I’ve looked up so far seem to be able to get me back to the last commit (no file) or the current state of the file (which I have anyway), but not the in-between of going to a previous version from the index, that’s never been part of a commit. Any hints on even whether or not this is possible (even a solid answer that it’s not, preferably with an explanation of why this is the case) would be appreciated.

  • 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-06-04T16:32:36+00:00Added an answer on June 4, 2026 at 4:32 pm

    There’s no direct way to get to the last staged version of a file. There’s no versioning of the index file, that’s what you are supposed to use commit for. In future you could consider making temporary commits more often (e.g. with commit --amend) and then at least your previous versions would be in your reflog (e.g. git log -g).

    However, all staged versions of all files will have been added to the git object database. You should be able to find them with git fsck --lost-found. This will write out all “dangling” blobs into .git/lost-found/other. Unfortunately they won’t be in any particular order or have their original file name but any lost blob should be in there somewhere.

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

Sidebar

Related Questions

I have a question that is similar, but not identical, to the one answered
I have a question that must be answer several times before, but I can't
I think I have question that looks similar to many old questions but it
I have a question that is similar to this SO question , but slightly
I have a question that is similar to this SO question , but slightly
I have a question that is similar to this question , but mine concerns
I have a question that may be quite naive, but I feel the need
I have a question that I'm ashamed to ask, but I'm going to have
I have a question that may sound odd, but being somewhat of a newbie,
I have a question that is probably very simple, but I cannot find an

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.