-1

enter image description hereOur .htaccess is part of the repo even though it is our .gitignore. So this is what I did.

git rm --cached .htaccess

That works, but when I do git status it shows the file as staged for commit to be deleted. If I make this commit, won't it delete it from the repo? I can unstage it, but then it shows it as modified. What I need to do is have the file being ignored locally but remain in the repo. I had to make a small change to the file but don't want the change in the repo.

sehummel
  • 5,476
  • 24
  • 90
  • 137
  • What do you mean by "delete it from the repo"? `git rm --cached ` tells Git to stop tracking ``; in other words, the file will *not* be included in subsequent commits. However, the file will remain in your working tree. – jub0bs Aug 15 '14 at 19:36
  • Either you have the file in the repo and changes are tracked, or you don't have the file in the repo but have it locally (and in .gitignore). – hunch_hunch Aug 15 '14 at 19:37
  • The file is in the repo. That's why I used git rm --cached. But it's tracking changes. How do I undo that? – sehummel Aug 15 '14 at 19:40
  • I did that but it is still being tracked. – sehummel Aug 15 '14 at 19:43
  • @sehummel, are you saying you did run a `git commit` after `git rm --cached .htaccess` (as suggested by @Jubobs), but .htaccess is still being tracked? Or have you not committed yet? – hunch_hunch Aug 15 '14 at 19:52
  • No I haven't committed yet. – sehummel Aug 15 '14 at 19:53
  • @sehummel After you commit, you're file will no longer be tracked. – jub0bs Aug 15 '14 at 19:53
  • But it won't delete it from the repo? – sehummel Aug 15 '14 at 19:53
  • 1
    Actually, `git rm --cached` *will* remove the file from the repo, just not from your working tree. Are you saying you want to ignore future changes to a file you have already committed? – Ajedi32 Aug 15 '14 at 19:57
  • This is why you shouldn't post answers in comments. The comments here are wrong, and would be properly downvoted if posted as an answer, but there is no downvote function for comments. Using `git rm --cached` removes the file from the index, and leaves it in the working directory. Committing that will record a commit to remove the file from the index. Any other users pulling from your repository will now have the commit that removes the file, *and* lose their local file. –  Aug 15 '14 at 19:58
  • @hvd I think what the OP means by *have the file being ignored locally but remain in the repo* is actually *have the file being ignored locally but remain in the working tree*. Otherwise, why would the OP want to use `git rm` at all? – jub0bs Aug 15 '14 at 20:02
  • @Jubobs So if the OP doesn't want to record any changes to the file, the OP surely *won't* want to record a change to remove it entirely, right? Did you notice that I specifically addressed what would happen for other users of the same repository? Do you think I am mistaken in what would happen for them, or do you think the OP won't mind having that happen for them? –  Aug 15 '14 at 20:05
  • @Jubobs I don't think the OP does want to use `git rm` at all. I think the OP used `git rm --cached` without completely understanding what it does, and that Ajedi32's link addresses how to accomplish that without the negative effects. –  Aug 15 '14 at 20:06
  • @hvd The question is confusing. What I understand from *our `.htaccess` is part of the repo even though it is our `.gitignore`* is: *we started tracking `.htaccess` by mistake and now it's being tracked even though it's listed in `.gitignore`*. But maybe I'm wrong; if I am, I'm happy to delete my comments and answer. – jub0bs Aug 15 '14 at 20:09
  • @Jubobs Now that is a fair question. I *think* it is contradicted by the explicit request of the OP to keep the file in the repository, but I will admit it is somewhat ambiguous. I think the repo has a `.htaccess` file, but the OP wants to use a different `.htaccess` file locally, and attempted to add it to `.gitignore` (even though it isn't in the repo) hoping to accomplish that. –  Aug 15 '14 at 20:14
  • @hvd Yes, that's what I understand as well now. Sorry about the confusion. In some of my earlier comments, I also wrote "repo" where I really meant "working tree". Double whammy... – jub0bs Aug 15 '14 at 20:16

1 Answers1

1

The correct answer to this issue git update-index --assume-unchanged <file>. git rm --cached <file> did remove the file from the repo.

sehummel
  • 5,476
  • 24
  • 90
  • 137