Possible to change supervisor for Ph.D defense in Germany? Currently I have reached the final stage of my Ph.D study in Germany. Nevertheless, I want to find a new supervisor within the same university or in other German university for Ph.D defense, is this possible? 

Long story short, due to the fact that my current supervisor could provide hardly any technical advice nor funding support for my PhD project in the last 2-3 years, the relationship between us became unpleasant and I seldom communicate with him (what can I expect?). Few months ago he told me that he would cancel the duty of supervision because of poor communication, but I can still defense my thesis under his name. I guess the actual reason why he was mad because I was not giving him the source codes of my work (literally for free).

Now my Ph.D thesis is almost finished (time mainly spent on numerical solvers programming based on open-source codes), and I want to find some professor who could at least give me some advice for my final work, and finish my Ph.D defense within 3-6 months. Assuming my future supervisor would agree with this (potentially continue working with him/her after the defense), but does this violate some regulations for Ph.D degree which requires someone staying in the university for a minimum period of time (e.g. enrolled semesters).
Most universities that I'm familiar with require an enrollment period of at least one year for doctoral students. Many additionally stipulate that this be an "on-campus" residency—that is, you can't be working offsite for a company or at another school. 

So you definitely need to check the regulations of anyone who would agree in principle to such a deal.

However, it is also worth considering the possibility that such a situation is one that a lot of faculty members would be reluctant to agree to participate in. Part of the reason for this is optics: they don't want to be seen as having "poached" another professor's graduate student, even if the reasons for doing so were benevolent. They may agree to a "co-supervision" situation instead, since that doesn't quite come across as badly.