How to ignore existing, committed files in git?

Possible duplicate:
GIT: Ignoring versioned files

There are many answers around .gitignore in Stackoverflow, but I haven't found an answer yet:

I have an existing git project with readme.md and a sample_folder/ , as at the top level. I want to remove them from my git (hub) repository as a whole. But I would like to ignore them, that is, to prevent them altogether, in a specific cloned local repository, that is, on the deployment machine.

.gitignore As far as I understand, this is only about ignoring files that are not associated with them? Honestly, I did not find anything that would hide (from pull + commit) things that were already committed ...

In the days of Perforce, I would just exclude it from the corresponding "client specification" (which is pretty close to a locally cloned repo):

 //whatever/myProject -//whatever/myProject/readme.md -//whatever/myProject/sample_folder 

Of course, I could settle for a second branch, where I just delete the readme and the entire sample folder. But then I would have to merge with every tiny correction from the "development". Something I would prefer to avoid ... I would prefer a local "exception" over the branch (tracked).

Also, I think git rm --cached whenever I commit (which can also happen now and after my โ€œrepo deploymentโ€) ...

+6
source share
3 answers

Perhaps I put the question wrong, but will your problem solve?

 git rm --cached readme.md sample_folder/* echo "readme.md" >>.gitignore echo "sample_folder/*" >>.gitignore git commit -am "Untracked some files" 
+5
source

It looks like you can use git validation as a deployment method. Sometimes it works, sometimes it takes a little more. If you need a little more when creating artifacts in the repository.

The most obvious way to handle this is to have a script deploy that pulls and then removes the extra directories and files. This, unfortunately, leaves you with a partial repository that can confuse people, and it adds a special script that must remember that it will be used and updated.

Another way to handle this is to have a deployment branch. Make a branch, delete offensive files and directories, and then pull it out of this branch. Yes, you will have to merge the changes from your development branch into the deployment. You see it as a burden, but it is a defense. If you quickly create development opportunities and deploy them just as quickly, you might have a problem with the deployment cycle.

You need a step between development and deployment in which you can review and test your changes. If nothing else, this will prevent developer A from failing to make a bad change, and administrator B exacerbates the error by unknowingly pulling it into production. You also want to be able to move towards development and share your work with other developers without fear that it will be put into production.

You may be the only person involved in development and deployment right now, but you cannot be later. If nothing else, this will protect you from accidentally pushing an unsustainable change in development, and then exacerbate this error by pulling it into a deployment before you can think.

+2
source

This is not a problem with .gitignore. If this is not code, you should track it in a separate repo through submodules and just not run any git submodule on the server. Or just a script deleting them on the deployment machine after checking.

0
source

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


All Articles