0

I am reading "The Art of Immutable Architecture by Michael L. Perry". It says:

Commits are immutable, and contain references to related commits.

..

This results in an immutable graph of commits.

..

When a conflict occurs, as it often does in source code, the developer finds within their local repository all of the information necessary to resolve it.

Based on all of this information, the developer can resolve the conflict themselves. They don’t need to involve the server. In fact, because of the nature of Git branches, they can choose to let the conflict stand as long as they please. There is no immediate need to for the conflict to be resolved before work can continue. But when a resolution is made, it is recorded as another commit. That commit becomes part of the history so that all parties involved can see that the conflict has been resolved and understand the effect of this resolution.

This mode of working is only possible because every commit is immutable.

I am not understanding what he is trying to imply? My confusion stems from the fact that history can be rewritten in git. As, far I know, we will still be able to merge conflict in git repository if history was rewritten.

I have checked What is the benefit of purely functional data structure?. What I understood is one reason for immutability can be (please correct me if i am wrong), as we can not rewrite commits, we do not need to lock them when pushing code.

Being said all these, I am still confused. What benefits does git get from immutability? I mead why did the architects of git decide to have immutable graph of commits?

Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87
  • 7
    History can be written, but the commits themselves are not. When you resolve a merge conflict, you are not editing the commits. You are creating brand new commits and switching over to the new ones. Suppose you resolved merge conflicts by editing old commits. What if two people edited the old commits differently? You'd have to merge the changes to the commits, and you are back where you started. – Raymond Chen Nov 14 '22 at 13:47
  • @RaymondChen it makes sense. – Ahmad Ismail Nov 14 '22 at 13:55
  • I think I found the answer in https://www.cronj.com/blog/immutable-mutable-data-structures-functional-javascript/ – Ahmad Ismail Nov 15 '22 at 09:19
  • 1
    That article isn't very good. "If git maintains history as a separate complete application code then there is a lot of unnecessary space used. Does git do that? NO!! NO!! NO!!" Um, actually, the answer is YES!! YES!! YES!! (See: tree objects.) A commit is a complete snapshot of the project, not a diff. The space savings comes from other parts of the design like Content Addressable Storage, Single Instance Storage, and packing. – Raymond Chen Nov 15 '22 at 12:50
  • Another resource is https://blog.git-init.com/immutable-snapshot-in-git/ – Ahmad Ismail Nov 16 '22 at 05:26
  • 1
    Side note: you mean [*imply*, not *infer*](https://www.dictionary.com/e/imply-vs-infer/). – torek Nov 20 '22 at 11:46

0 Answers0