0

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!

Natalia Ivanova
  • 60
  • 1
  • 10

1 Answers1

0

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

Community
  • 1
  • 1
d4Rk
  • 6,622
  • 5
  • 46
  • 60
  • Thank you! Yes, I thought about ignoring; now it's time to implement. Files I'm talking about are a part of the project but I don't need track them into git history as no change are made for them. – Natalia Ivanova Feb 13 '16 at 07:55
  • So that's some kind of local configs? But maybe then even "assume unchanged" can be an option. Should you get a "base version" of those files, when you do a fresh checkout/clone (e.g. when someone's new on the project)? – d4Rk Feb 13 '16 at 08:02
  • Yes, I should. These are additional scripts and the project won't work properly without them. Still, I can't bring the folder back to the previous versions of the project by assume-unchanged. (It was there before the last commit). Neither can I prevent the folder from adding to staging area after `--assume-unchanged` was run on it. I ran both `git update-index --assume-unchanged` and `git ls-files | tr '\n' ' ' | xargs git update-index --assume-unchanged` from inside this folder and then `git add [folder name]` and `git status` and it's there! – Natalia Ivanova Feb 13 '16 at 10:36
  • Are those scripts the same for everyone? Then just, add them to the repo (without assuming or ignoring anything). If there's some machine/user specific configuration on them, I would not add them. – d4Rk Feb 13 '16 at 12:16
  • Well, they are already added. But when I checkout to some past commit (I sometimes need) they are eliminated... – Natalia Ivanova Feb 13 '16 at 14:51