0

I made an Angular project and pushed it on github ( I don't know much about git ). After pushing, I saw there was just one folder with a right arrow on it and when clicking on it didn't result in anything. So I thought of removing it and pushing it again. So, by using internet, I found this code.

git rm -rf folder-name

Using this, the original folder from local was deleted and now here I am panicking how I can recover that back.

Any help and suggestions would be helpful plz.

techieansh
  • 11
  • 3

1 Answers1

0

Assuming that what you mean is:

When I go to GitHub and view the commit, I see this icon: folder with a white arrow on it

what it means is that you committed a "naked" gitlink, i.e., a reference to some other Git repository. This is half of a submodule: a submodule is a reference to some other Git repository that includes the instructions that Git needs to clone that other Git repository.

Removing the gitlink and committing merely made a new commit in which there is no gitlink any more. This did not damage anything. All new commits merely add on to your existing repository; the old commits continue to exist. Checking out the older commit, or using git revert to back out the changes made by a commit you dislike, will "undo" that effect.

The key difference between checking out an old commit and using git revert is that the former simply gets you the old commit, as a "detached HEAD". You can work with it, and even create a new branch from this point if you like. Using git revert tells Git: make another, even-newer commit that undoes the effect of some previous commit. That is, instead of going back in time, you go forward in time but put things back. One method is vaguely analogous to "Gosh, I broke my vase, let me go back in time to before I broke it" and the other is "Gosh, I broke my vase, let me glue it back together".

You almost never want to have a "naked" gitlink. Whether you want to have a real submodule, or just incorporate some other Git repository's currently-checked-out-files into a new commit in this repository, is another question entirely. There are more details at GitHub folders have a white arrow on them.

torek
  • 448,244
  • 59
  • 642
  • 775
  • After my first commit only I got the naked folder. And then I run the rm -rf command which removed the folder from the local. Now I don't have any access to that folder anywhere. – techieansh Oct 11 '21 at 08:38
  • It's still in the old commits. New commits *add*. Even if you remove every file and commit, you've just *added* things. Going back to the old commit gets the files back. – torek Oct 11 '21 at 10:04