git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Newbie grief

From
SRSeth Robertson <in-gitvger@baka.org>
Date
May 1, 2012, 01:37 UTC
Message-ID
<201205010137.q411bxaU002449@no.baka.org>
In-Reply-To
<4F9F28F5.2020403@palm.com>
In message <4F9F28F5.2020403@palm.com>, Rich Pixley writes:
    On 4/30/12 16:31 , Seth Robertson wrote:
    >      It seems that git is allergic to the dual head branch solution or
    >      something, which is surprising and disappointing.
    >
    > Git tracks your version of master separately from each other remote's
    > master.  This is exactly dual/multiple heads.
    No, it isn't at all.
    Multiple heads are the idea that a single commit can "branch" in the
    repository and that /both /commits can be HEADS of the same branch at
    once in a single repository.  This allows a potential collision to exist
    in the repository and to be pushed and pulled through multiple
    repositories.  It also largely eliminates this entire discussion since
    each of the intermediate repositories between, say, you and I can carry
    the collision.  Either you or I, at will, can merge these heads just
    like we'd merge any other two commits, push, etc.
    That would seem to be the obvious and intuitive behavior, not
    arbitrarily preventing the transfer.

I still don't see how git isn't providing this to you, with the caveat that in git, a single commit with a specific SHA1 hash is constant. You may modify it (making it a new commit), modify its history (making it a new commit), or add new commits after it. Git doesn't number commits the way other VCS do, which may be the source of confusion.

A specific commit with a specific SHA1 can be at the head of multiple branches. Those branch may be local to the repository, local tracking branches, or remote tracking branches.

Contrarywise, the head of the "master" (or any) branch (or ref) may point to any SHA1. My master branch may point to one SHA1, yours may point to another. You can look at my version of master and I can look at your version of master (permissions permitting). After appropriate network operations, either you, or I, at will, can merge these heads just like we'd merge any other two commits, push, etc. With appropriate naming conventions, we can even continue parallel updates where I can make updates to your version of master and you can make updates to my version of master, in addition to our own.

For example, in the diagram http://mercurial.selenic.com/wiki/Head rev2 might be your version of master and rev3 might be my version. Both might exist in my repository and both might exist in your repository, and both might have the symbolic name "master" associated with it, and git would keep it entirely straight.

    >    What git *does* forbid
    > (by default) is:
    >
    > 1: Letting you update someone else's checked out (non-bare) repository
    > underneath them
    Yeah.  That "underneath them" thing is confusing.  I don't see any
    reason why that should necessarily be so.
    Git knows what commit is checked out.  That's HEAD, yes?  So what's
    wrong with letting it collect other commits from other repositories
    while your working directory sits?

It does! It can! What is forbidden is for me update what you have checked out. Can you conceive of a revision control system where I commit I would make would change what you have checked out? (Well, I can, ClearCase with dynamic views, and it is more horrible than you can imagine—I've had compile fail because the files changed underneath my feet between the start of the compile and the end of the compile). And what happens if the file I changed is also the file you are in the middle of changing? Is your change going to overwrite mine? Is mine going to overwrite yours? This way leads to insanity.

    You can always commit your change right on top of what's checked
    out, creating a second head for that branch.

With git, you must always commit your change right on top of what's checked out, though of course you may decide to change what's checked out and "float" the changes you made over to the new head (trivial, as long as there are not conflicts between the two heads and the changes you made). However, only the user of the repository is allowed to do this. A remote user is not allowed to change what's checked out.

    Yes, I've read that git-diff, etc, are all making assumptions that fail
    in this case, but there's nothing significantly different about
    collecting commits to other branches and collecting commits to the
    branch you're currently checked out from.

Yes there is. Consider this use case. You can I both spot DIFFERENT bugs. You and I both start editing filea. I fix my problem one way which involves lines 10, 100, and 500, you fix your problem which involves line 10, 100, and 200. I'm typing faster than you so I commit/push first. If I can update your HEAD, at that point I've changed the file you are editing. You save and my change is lost.

Now this is where you say, if git only supported multiple HEADs the problem would go away. I could update my version of master and you could update your version of master and there would be no conflict. And...of course you can with git. I don't update your master, what you have checked out, I update what you know is my master. Then when you are done, you get to say "merge my master with your master" or "instead of committing this change on my branch, let me try this last change I made on top of the changes you made" or whatever you want to say.

    > 2: Letting you update someone else's repository if they have more
    > recent changes than you do.
    Again, if they have more recent changes, then my line of changes should
    create a fresh HEAD on that branch.  Then the repositories hold all of
    our changes to be merged at our leisure.

And...git does this. Your changes are made on your HEAD (your branch). My changes are made on my HEAD (my branch). Never the twain shall meet until someone says "merge" (or "rebase").

The key to all of this is the namespace naming convention. refs/remotes/<remotename>/<branchname> (or more informally <remotename>/<branchname>) is a remote tracking branch, or my idea of what your branches (HEADs) currently are. These are (kinda/sorta) read-only reference which are only updated when you specifically ask them to be updated, or if I decide to update what you believe I have (kinda rude, but allowed).

So let us consider a specific example. There is a repository which everyone call's "Rich" (they don't need to use the same name, but it reduces confusion), a repository everyone calls "Seth", and a central repository everyone calls "origin".

Location Branchname -------- ---------- origin foo (bare) rodger foo rodger origin/foo rodger seth/foo seth foo seth origin/foo seth rodger/foo

I make a change in my foo. I can push the change into origin's foo, rodger's seth/foo (and technically origin/foo but that is more than just rude). You can take my change and store it in seth/foo.

At any point, after you have the changes (either because I push them or you fetch them) you can then merge your work with my work.

So...what's not possible?
					-Seth Robertson
Previous: Philippe VaucherNext: Rich Pixley
Message 68 of 100 in “Newbie grief”
  1. Rich PixleyApr 30, 2012
  2. Seth RobertsonApr 30, 2012
  3. Rich PixleyMay 1, 2012
  4. Junio C HamanoMay 1, 2012
  5. Rich PixleyMay 1, 2012
  6. Sitaram ChamartyMay 1, 2012
  7. Ted Ts'oMay 1, 2012
  8. Sitaram ChamartyMay 1, 2012
  9. Rich PixleyMay 1, 2012
  10. Michael WittenMay 1, 2012
  11. Rich PixleyMay 1, 2012
  12. Jakub NarebskiMay 2, 2012
  13. Randal L. SchwartzMay 1, 2012
  14. Rich PixleyMay 1, 2012
  15. Randal L. SchwartzMay 1, 2012
  16. Junio C HamanoMay 1, 2012
  17. Rich PixleyMay 1, 2012
  18. Randal L. SchwartzMay 1, 2012
  19. Rich PixleyMay 1, 2012
  20. Michael WittenMay 1, 2012
  21. Philip OakleyMay 1, 2012
  22. Hallvard Breien FurusethMay 3, 2012
  23. Rich PixleyMay 3, 2012
  24. Hallvard Breien FurusethMay 3, 2012
  25. Hallvard Breien FurusethMay 3, 2012
  26. Rich PixleyMay 3, 2012
  27. Junio C HamanoMay 3, 2012
  28. Rich PixleyMay 3, 2012
  29. Randal L. SchwartzMay 3, 2012
  30. Junio C HamanoMay 3, 2012
  31. Felipe ContrerasMay 4, 2012
  32. Felipe ContrerasMay 4, 2012
  33. Michael WittenMay 4, 2012
  34. Rich PixleyMay 1, 2012
  35. Randal L. SchwartzMay 1, 2012
  36. Rich PixleyMay 1, 2012
  37. Andreas EricssonMay 1, 2012
  38. PJ WeisbergMay 1, 2012
  39. Rich PixleyMay 3, 2012
  40. Nathan GrayMay 3, 2012
  41. Rich PixleyMay 3, 2012
  42. Randal L. SchwartzMay 3, 2012
  43. Rich PixleyMay 3, 2012
  44. Mark BrownMay 4, 2012
  45. Rich PixleyMay 4, 2012
  46. Jakub NarebskiMay 4, 2012
  47. Mark BrownMay 4, 2012
  48. Hallvard Breien FurusethMay 2, 2012
  49. Michael WittenMay 2, 2012
  50. Hallvard Breien FurusethMay 3, 2012
  51. Randal L. SchwartzMay 3, 2012
  52. Michael WittenMay 3, 2012
  53. Hallvard Breien FurusethMay 3, 2012
  54. Michael WittenMay 3, 2012
  55. Rich PixleyMay 3, 2012
  56. Ted Ts'oMay 3, 2012
  57. Felipe ContrerasMay 1, 2012
  58. Rich PixleyMay 3, 2012
  59. Rich PixleyMay 3, 2012
  60. Andreas EricssonMay 4, 2012
  61. Stephen BashMay 4, 2012
  62. Mark BrownMay 4, 2012
  63. Felipe ContrerasMay 4, 2012
  64. Rich PixleyMay 1, 2012
  65. Jan KrügerApr 30, 2012
  66. Rich PixleyMay 1, 2012
  67. Philippe VaucherMay 2, 2012
  68. Seth RobertsonMay 1, 2012
  69. Rich PixleyMay 1, 2012
  70. Michael WittenMay 1, 2012
  71. Junio C HamanoMay 1, 2012
  72. Michael WittenMay 1, 2012
  73. Rich PixleyMay 1, 2012
  74. Rich PixleyMay 1, 2012
  75. Rich PixleyMay 3, 2012
  76. Ronan KeryellMay 3, 2012
  77. Junio C HamanoMay 3, 2012
  78. Ronan KeryellMay 3, 2012
  79. Rich PixleyMay 3, 2012
  80. Rich PixleyMay 3, 2012
  81. Illia BobyrMay 4, 2012
  82. Nathan GrayMay 4, 2012
  83. Michael WittenMay 4, 2012
  84. Junio C HamanoMay 4, 2012
  85. Carlos Martín NietoMay 4, 2012
  86. Junio C HamanoMay 4, 2012
  87. Junio C HamanoMay 4, 2012
  88. Nathan GrayMay 4, 2012
  89. Illia BobyrMay 4, 2012
  90. Rich PixleyMay 4, 2012
  91. Rich PixleyMay 4, 2012
  92. Michael WittenMay 4, 2012
  93. Andrew SayersMay 4, 2012
  94. Jérôme BenoitMay 4, 2012
  95. Felipe ContrerasMay 4, 2012
  96. Junio C HamanoMay 4, 2012
  97. Felipe ContrerasMay 4, 2012
  98. Rich PixleyMay 4, 2012
  99. Felipe ContrerasMay 4, 2012
  100. Sitaram ChamartyMay 2, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.