English feliratok

← Conflict Detection - How to Use Git and GitHub

Beágyazókód kérése
5 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. In this example, how can Git tell if B prime and
  2. B double prime are modified versions of B or
  3. if the users just deleted B and wrote entirely new lines in the same area?
  4. Rather than expending a lot of effort trying to figure this sort of thing out,
  5. Git just notes that the lines are different and goes from there.
  6. So how does Git know whether or not there should be a merge conflict?
  7. Consider the following two examples.
  8. In both cases, we start with two identical copies of the same file.
  9. In the first case,
  10. two different contributors add new functions to the bottom of the files.
  11. These are different functions that don't interact with each other and
  12. have nothing to do with one another.
  13. However, in the second case, two different contributors add
  14. different implementations of the same function with different names.
  15. In the first case, you pretty clearly want both functions to be included, but
  16. in the second situation, you probably only want one version of the function,
  17. probably whichever one is either more memory efficient or
  18. faster, depending on what you're going for.
  19. But Git can't really tell these two options apart.
  20. It would take some pretty sophisticated machine learning to do this.
  21. And this is only one possible scenario.
  22. Making Git smart enough to figure out all the possible cases where you'd want to
  23. auto-merge would be a huge undertaking.
  24. So instead, Git just assumes that if you're merging together two commits that
  25. have changes in the same general area, the authors will want to know about it
  26. and have the chance to figure out for themselves which change to keep.
  27. This decision to ask the user whenever there's any ambiguity at
  28. all does sometimes lead to situations where it seems really obvious to you,
  29. as an expert on the content, how to resolve the conflict.
  30. But Git brings it to your attention anyway.
  31. While this may be annoying, it's significantly better than if Git tried to
  32. guess too often, which could lead to weird conglomerate changes that don't
  33. really make any sense and probably wouldn't compile or run.