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

  • Home
  • SEARCH
  • 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 7416427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:29:39+00:00 2026-05-29T07:29:39+00:00

I was setting up my first git repository and did the following, git init

  • 0

I was setting up my first git repository and did the following,

git init

follow by some git-config stuff to setup the remote server. I then did

git add directory
git status

Whoops, I added some files which I did not want. Okay, so I should git rm to remove the directory from the commit list and start again

git rm directory

At this point I should have read the console message and documentation properly….but didn’t. So I ran

git rm directory -r -f

Huh? Where did my directory go? Ah, okay, git has removed it so it is “not there” any more. So lets try,

git status
git reset --hard

After no success, some error messages and a bunch of web searches, I realised my faux pas. I should have used

git rm -r --cached directory

which would have removed it from the commit list, but not from my file system. Whoops. Fortunately nothing serious lost.

It seems like there should be a way to recover from this, but most of my searches end up pointing to the “–cached” option…and it is a bit late for that. There are no commits, so I can’t just revert/pull the files (there was only a local copy).

Is it possible to get those files back?

  • 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-29T07:29:40+00:00Added an answer on May 29, 2026 at 7:29 am

    There are no commits, so I can’t just revert/pull the files (there was only a local copy)

    and

    Is it possible to get those files back?

    The answer is no.

    There are no commits, hence you are not using source control.

    The files never entered the object database. In general, you can never get uncomitted stuff back in git. You can most often get previously committed stuff back.

    Rule of thumb: commit often

    Edit

    See also

    • my own answer here https://stackoverflow.com/a/6780036/85371 (look for other sources of backup) and
    • someone else’s answer https://stackoverflow.com/a/6780036/85371 two months later.

    I accidentally ran git reset --hard on my repo today too while having uncommitted changes too today. To get it back, I ran git fsck --lost-found, which wrote all unreferenced blobs to <path to repo>/.git/lost-found/. Since the files were uncommitted, I found them in the other directory within the <path to repo>/.git/lost-found/. From there, I can see the uncommitted files, copy out the blobs, and rename them.

    Note: This only works if you added the files you want to save to the index (using git add .). If the files weren’t in the index, they are lost.

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

Sidebar

Related Questions

I'm setting up My First Git Repo, and on running; git config --list I've
I have tried following how-set-up-your-own-private-git-server-linux and private-remote-git-repositories-ubuntu-linode but I am still having problems. My
A random class definition: class ABC: x = 6 Setting some values, first for
I'm setting up my first Hudson + Git project (previously done many with Hudson
This is the very first time I have set up a git server, as
I'm setting up my first site using the asp authentication provider and using the
I'm setting up my first development Linux box - a netbook actually. I'm quite
I'm setting up my first symfony project, and am having trouble with the schema.
I am setting up an Oracle connection for NHibernate for the first time. I
I'm setting up a public site and the first thing on my mind is

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.