简体   繁体   中英

Git merge from a different branch reverts code

I have added an image that describes the flow of our git commits. Basically, two users checkout a develop branch. Then they create their own feature branches and make changes to one file (different parts of the file, so no conflicts). First user changes the file and merges to the develop branch early. Later second user who has been working on the earlier copy of the file, makes their new changes, merges to develop as well. Merge from the second user merges without conflict but reverts changes made by the first user. How do we prevent this? Sometimes minor details are missed when reviewing pull requests that do not have any merge conflicts.

在此处输入图像描述

Please ask second user to pull the changes from develop before merging.

git pull --rebase

Try to do a rebase and fix the conflicts that may arise:

git rebase origin/BRANCH

Then if there is conflict try to fix it first.

This will make sure their changes gets to you first and you can deal with them, before commit / push. It is always best to rebase so changes you made are still in the commit.

Here is the below solution: Two user and two feature branch

1.First user merge changes of featureBranch1 to develop 2.Second user do changes in featureBranch2, but second user has to do below steps to incorporate changes done by first user into develop branch after merge

git rebase develop (This moves the entire featureBranch2 to begin on the tip of the develop branch, effectively incorporating all of the new commits in develop)

Sorry about the delayed response. The solution was easier than using rebase. The second user has to simply call git pull origin development while staying in their feature branch before merging the pull request. If there are conflicts while pulling, the user has to resolve conflicts and push to their branch. Then the reviewer should review the pull request again and approve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM