Git: merging with a frequently updated remote branch?

Just wondering what is the usual practice for combining back to the owner when the head was probably re-updated from the last pull to the merger. To illustrate, in the following diagram M is the proposed merge point, but since the HEAD master updates to A1 by the time M is completed and ready for pushing, M1 will become the new intended merge point, in other words, a new merger must be undertaken.

master-----A----A1---... \ \ M M1 / / local------B------ 

Please note that I would prefer not to combine M and A1, because there may be an A2, A3 down line, and if the problem recurs it just looks too confusing for me to additional unforeseen mergers. If the changes in the local one are quite independent of the changes in the master, sometimes I just rebuild the top of the master, which, in my opinion, is a simpler solution. But in other cases, I really hope that I can “reuse” the merger work that I did for M, for M1.

+4
source share
4 answers

I finally understood what I had in mind, and the solution is to simply reinstall the merge commit as described here: Uninstalling Git Compilation

0
source

Let's say each person on a team maintains their own repository. One person on the team maintains what is collectively known as the main repository.

As team members work, they can pull out of the main, but they do not click on the main. During attraction, if there is a merge conflict, this person will correct his own code.

Now, the owner of main needs at least read access to each member repository. Then the owner of main pulls from each repository in turn. If there are no merge conflicts, no problem. If there is a conflict, the owner of main interrupts the commit and allows the person who owns the code to fix the conflict. Let's take a closer look at this detail.

  • main pulls from bob - ok; merger completed and published
  • main extracts from tom - conflict; merger canceled
  • owner main tells tom to display the latest changes and fix the conflict
  • tom can fix the conflict itself and then tell main try again
  • main pulls from tom - ok

This process is simply repeated every day, or often your integration cycle.

While this definitely puts a burden on one person, this person should not fix any conflicts, this is work that can be automated with the right motivation. This is how Linus does this to control the kernel.

+2
source

It looks like a job for git rebase .

Workflow

You are working on a separate branch (call it local ) and you will make a few commits. When you are ready to push your changes, check the master branch and do a git pull . Checkout local and make git rebase master . This command will:

  • postpone your changes / commits (to local ), since master and local diverged,
  • do a quick merge with the master branch,
  • Confirm your initial changes to your local branch. Keep in mind that the message, author, and commit date remain the same, BUT hashing commit CHANGES . This is because all objects (commits, trees, blobs) are immutable, and since the parent property of the commit changes, git will create another commit.

The consequences of git rebase

Since the hash code of the commit is changing, you only need to reinstall on LOCAL branches (i.e. NOT pressed on the remote).

+1
source

We use a registration token to coordinate this kind of problem. The one who has it is sure that no one checks the owner until he is released.

If you are together with other developers checking in your head, use a physical token (elephant / monkey / chicken - anything really is better than better).

When we had distributed development, we used a wiki page with a table, where the top is a face with a “token”.

+1
source

Source: https://habr.com/ru/post/1383169/


All Articles