Scan the folder locally in git and click on production without deleting

I have an images folder that was used for tracking and which I did not track using: git rm -r --cached images .

I also added images/ to my gitignore. However, I am afraid that when I lock and pull onto my production server, the image folder will be deleted. The reason is that the github application actually shows that the files are deleted.

So, how can I prevent locally deleted, and then not verified and ignored files from being deleted on the production server on git pull ?

+6
source share
4 answers

With git rm --cached files are removed from git, although they are still in your local folder. Therefore, after you push files on the server will be deleted, as well as other repositories when they pull .

It is best to use git update-index .

 git update-index --assume-unchanged images/* 

He must fulfill your requirement. The only problem is that if other users change these image files and click on the git server, you will still get these changes when you pull .

+7
source

I really did it differently. Since there are only 2 people using git (I and another developer), we just don't track folders locally. Then I made a new .gitignore and pulled it to the production server. Subsequently, I did not track the folder on the production server and voila!

+1
source

Another alternative that might be better for new teammates is this: to add the necessary directories, but without their contents:

 **/images/* !**/images/readme.md 

Since Git does not apply to empty directories, the trick is to tell Git not to track anything in the images directory. But in order to create a directory in the first place, we need a file, so at the end we say β€œdo not track anything in this directory except thisβ€œ Reading me ”.

0
source
 git rm --ignore-unmatch --cached my_folder/**/** 

this will track ALL FILES in "my_folder" and its subfolders (one level lower)

0
source

Source: https://habr.com/ru/post/974829/


All Articles