A
A
Anastasia Lashkevich2017-09-25 09:56:21
git
Anastasia Lashkevich, 2017-09-25 09:56:21

Removing files from git version control: why does git remove files that are out of its control?

I want to remove a file from version control, it's about the .htaccess file, but I don't want to remove the file itself.
That's why I use the following commands in my repository:
git rm --cached htaccess
git add .
git commit -m "removed the .htaccess file from version control"
git push
on this server the .htaccess file remains intact
-----
these changes end up in the remote repository
----
on the other server I get these changes with
git pull
in As a result, git removes the .htaccess file from the server that received the changes
AND I restore the .htacces for it from a backup, why is this happening? why does git delete a file?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
RidgeA, 2017-09-25
@RidgeA

you still need to add to .gitignore.
git commits and removes the file.
It does not delete on your machine, because `--cached`

V
Victor, 2017-09-25
@v_decadence

No way. Git is instructed by you to delete the file (it leaves it on your copy with the --cached switch).
When merging the changes, he repeats this at another site and deletes the file (this time without saving, because he does not remember this key for everyone, for him it is just a deletion).
You need to delete this file, add it to .gitignore and then manually add it back on each site after deletion.
Or you need to do git rm --cached on each site, then when merging, Git will see that the file has already been deleted and will not do anything with it.
It's a chore, but I myself did not find another way.

A
Anastasia Lashkevich, 2017-09-25
@AnastasiaL

in .gitignore first of all added. And how to make sure that it does not delete on others too?

A
aol-nnov, 2017-09-25
@aol-nnov

Therefore, I use the following commands in my repository:
git rm --cached htaccess

For starters, htaccess and .htaccess are two big differences, as they say here in Odessa.
otherwise, RidgeA said everything correctly :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question