Search code examples
gitrevert

in Git, once commited folder disappears on checkout


I'm new to Git and here's my problem: I accidentally added to commit a folder with files essential to my project but unchanged (say, Downloaded/). I didn't track this folder before, it just stayed untouched from commit to commit. Now, after this last commit, when I make a checkout to some previous commit, the Downloaded/ folder disappears from a file manager.

What is the correct way to revert that change and bring the folder back? I don't want to track it, still, maybe I should?

I tried this:

git reset HEAD

and this:

git update-index --assume-unchanged Downloaded/

I can solve this 'manually', as I have a backup of the folder. Still, for learning reasons, I prefer to do it in git.

I'll appreciate any help!


Solution

  • Did you think about ignoring such files, to avoid mistakes like this? https://help.github.com/articles/ignoring-files/

    You should not have to think about, what files you are allowed to commit, this should be set up in the repo (e.g. using .gitignore, configs, whatever).

    But as you said, maybe you should track them, but that's up to you.. Do those files belong to the repo/project? Should they be under version control?

    For a temp directory (e.g. downloads?), I would just ignore it.

    In your case, I would:

    • add a .gitignore file
    • and then remove those files from the repo using git rm --cached <file>

    Actually that's pretty much, what you are looking for: gitignore after commit