Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Undo delete of an ignored file in Git

I have done something extremely stupid. I tried to fix some merge conflicts in Git, and I don’t know what I did, but I deleted my media folder (indirectly), in which I had all the images I needed for my website. I could’ve pulled from Git, except I can’t because .gitignore ignores the media folder. I have no idea what to do.

Here’s what I did:
I pulled from git, but it said error: Your local changes to the following files would be overwritten by merge. So I stashed my directory and then tried to pull again. Because of a few merge conflicts, I stashed, committed, and then tried to reset HEAD to the previous commit (I think this is where the folder got deleted) after git checkout -- ..

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Fortunately : the actions you descibe do not include things that would erase untracked files from disk. Your media folder probably ended up in the stash.

Run git stash list to inspect how many stashes you have.

You can use regular git commands to inspect the content of a stash. For example, you can list the files in a stash using git ls-tree :

git ls-tree stash@{xx}
git ls-tree -r --name-only stash@{xx}:media/folder

# actually, 'git ls-tree' works on any commit (not just stashes)

If you see the content you want in one of these stashes, just run :

git stash apply stash@{xx}

# if its the first stash (stash@{0}), shortcut is :
git stash apply
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading