3

I am using git remove git rm. I made the simple/stupid mistake of manually deleting a folder with all the files in it BEFORE I used git rm.

Now I have >15 files that I want to delete from my repo but NOT type out.

Is there a way to do this?

git status

deleted:    Literature/abc.md
deleted:    Literature/acdf.pdf
deleted:    Literature/dsfsdf.pdf
deleted:    Literature/dfgdfs.pdf
deleted:    Literature/sgadfgaa.md
deleted:    Literature/sdsds.pdf
deleted:    Literature/sddvasds.rmd
deleted:    Literature/ddsds.md
deleted:    Literature/fsdfsdsd.png

3 Answers 3

1

Yes they're deleted from your worktree, but these files were saved in last revision*, so you just have to restore these files as they were at last commit :

git checkout -- full/path/to/Literature/

then rm them as you intended in the first place.

* (unless these are new added files but you didn't say so)

Sign up to request clarification or add additional context in comments.

2 Comments

i did a git checkout {number} but now I have a detached head.
@oaxacamatt That's not a problem, just checkout your branch again with git checkout <yourBranch>. But I don't get why you typed that. Was it on purpose? The -- in my code is not a placeholder for numbers, just a way to tell git "anything after that is not parameters but file pathes" Can you share what you typed exactly?
1

If you have no other changes currently, and you are sure you need to revert back to the last committed state,

you can use , git reset --hard which moves the HEAD to last committed hash and discarding all your local changes after that commit

Or, safer way is to do a git reset {path to your deleted folder} first, to make the files unstaged for next commit, and then doing git checkout -- {path to your deleted folder} as suggested by @RomainValeri

Comments

0

You can use the command

git rm -r --cached 

For more details follow the link Bit Bucket Documentation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.