7

I'm mastering a development team where everyone worked with Eclipse and the same formatting settings.

Now some of the developers have reasons to switch to other IDEs, which format source code differently. So, when they now push to the git origin repo, git notices a a lot of cosmetic differences. Unfortunately, this is a big problem for some of the developers to get their head around.

Is there a way to get git - maybe by using hooks - to reformat everything on push or preferably commit, so the code in the repo is always formatted IDE independently?

I'm assuming we are not the first team in git-history to have that problem, so I hope there is a prefab solution or at least some best practices.

4

1 に答える 1

5

これを確実に行う唯一の方法はサーバー側です (クライアント側のフックは、セキュリティ上の理由からクローン中に自動的に設定されないため、コメントの 1 つで提案されているようにクライアント側で行う場合は、各開発者が手動で行う必要があります)。そのフックを一度設定します)。

そこでは、理論的には、受信した更新を操作することができます... しかし、それはかなり複雑なことです。ただし、実際の問題は、それが完了すると、ローカルには手付かずの独自のコミットがあり、サーバーには変更されたコミットがあることです。これは問題を引き起こしています。ここでプル/マージを行うと、git は変更されていない履歴と変更された履歴を結合し、突然、すべてのコミットが 2 回行われます。

適切にフォーマットされたコードのみが最終的にリポジトリに格納されるようにしたい場合は、不適切なフォーマットのコードを拒否する方がはるかに簡単で、問題も少なくなります。もちろん、これは実際にはかなり厄介なことですが、それはあなたが決定しなければならないトレードオフです。

開発者にそのローカル フックのセットアップを行わせることができると仮定すると、ローカルの pre-commit フックはほぼ確実に記述が容易になり、実際には問題が少なくなります。ただし、さまざまな方法でバイパスされる可能性があるため、鉄壁の保証はありません。 .

于 2013-03-21T13:04:43.323 に答える