Search code examples
gitgit-mergegit-push

Merging all the commits centrally


To simplify the situation suppose two users commit history is like

A -> B -> C     A -> B -> D  # and Repo at  A -> B

and both two user try to push at same time. First user will get chance first and now repo is at

A -> B -> C

Now 2nd user must have to pull again before pushing so he's now at

A -> B -> C -> D or A -> B -> D -> C

So this rises two questions first is how this Merge happens(on timestamps..!)? How git decides which commits comes first C or D. And second is why this merging thing Cant be performed at Remote or Central Repo.(assuming there is no merge conflicts) ?

I am thinking about using git for some other synching technique So suppose there is N users trying to push something at the same time then each user will have to pull N-1 times before being able to push.

So assuming there is no merge conflicts is there a way to perform a merge centrally. Just to clarify that user is going to pull eventually but i just want to avoid that N-1 pulls.


Solution

  • each user will have to pull N-1 times before being able to push

    They won't: each user will pull then try again to push. If another user has not pushed in the meantime, that one pull will succeed.
    The chances to have to pull n-1 times (meaning each push fails because one other user has just pushed) are very low.

    don't you think it can be a major issue in practice if 100 user trying to push at the same time and last 1 will have to pull 99 time before being able to push.?

    No, because if in that case, you would avoid that issue by allowing each user to push into a dedicated branch (one per user).
    Such a concurrent operation would be resolved on the server side (with merges done in an integration branch). It would not be left to the clients side (where what you describe would be too cumbersome to resolve)

    what about using queuing system (rabbitmq probably) to transfer all git objects to a bare repo and setting the head as required. what is your thought on it. would it be nice in clustering situation?

    You need to make sure the transfer won't fail (hence one branch per user)
    Then, on that bare git repo, another process can try and merge any new commit pushed to a user branch. If it fails because of conflicts, it would send a notification email for an integrator to resolve the situation.