Background: if you didn't run the "git pull origin master" before the first commit of the update, or didn't run "git pull origin master --rebase" when you want to upload new patch to an under review commit, someone else edited and merged other code in the same file(s), the code difference with the merged code in remote will be detected by Gerrit, then Gerrit reports "Merge Conflict" status. This page is written in order to tell you how to fix this issue.
Step 1: Back to local master branch with the command "git checkout master" or re-clone it.
$: git checkout master
Step 2: Run "git pull" to make sure local master branch is up to date as remote master.
$: git pull origin
Step 3: Create a new local branch, for example "myexample" with the command "git checkout -b myexample". Then the git bash will show you are in it likes "arnold.huang@RSZ-ED-000247 MINGW64 /d/Automation Team/Automation (myexample)"
$: git checkout -b DEV
Step 4: Open the gerrit webpage which has the "merge conflict" issue, log in with your account and click the "Download" button, switch to "SSH" page, copy the pull command :
$: git pull "xxxxxxxxxxxxxxxxxxxxxxxxxxx" refs/changes/49/49/1
Step 5: Run the copied pull command in your local branch. Git will tell you which file has conflict,
remote: Counting objects: 39, done
remote: Finding sources: 100% (32/32)
remote: Total 32 (delta 15), reused 32 (delta 15)
Unpacking objects: 100% (32/32), 120.56 KiB | 93.00 KiB/s, done.
From ssh://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
* branch refs/changes/49/49/1 -> FETCH_HEAD
Auto-merging AutomationProject/Project/Generic/__init__.py
CONFLICT (content): Merge conflict in AutomationProject/Project/Generic/__init__.py
Automatic merge failed; fix conflicts and then commit the result.
Step 6: Check the "git log" to see if the target commit is pulled to local. The log shows that the target commit is not present. We need to fix the conflict then it can merge. And at the tail of command prompt it shows " (<your branch name>|MERGING)"
$ git log
commit 966a1b1e4393eb2aac0dbecb11f7b4d9dc526e60 (HEAD -> myexample, origin/master, origin/HEAD, master)
Author: Bruce Liu <bruce.liu@xxx.com>
Date: Mon Jul 19 15:25:56 2021 +0800
Optimize NVRead.py
Change GetNVFile() and the csv filename, for easy compare the NV value
difference between different FW versions.
Change-Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Step 7: Check the file which has conflict issue , to see where is the conflict and figure out how to fix. In our example, the conflict is:
<<<<<<< HEAD
import Project.Base.ModemCtrl as ModemCtrl
=======
import Project.Base.Smack as Smack
>>>>>>> 86b51290672e3a79c5ee4cd51b3907878dd3ff4d
It means someone else added a ModemCtrl as new line , but in "__init__.py" in this example, no "ModemCtrl" here so make a conflict. So we just re-edit the "__init__.py", remove the line "<<<<<<<HEAD", "=======" and ">>>>> <commit hash>", keepboth of ModemCtrl line and Smack Line, and save it.
Step 8: Run "git status" and "git add <your file>" to confirm your modification is done. In this example. "git add AutomationProject/Project/Generic/__init__.py".
$ git status
Step 9: Run "git commit" (not commit --amend). Modify the commit message to describe your update.
$ git commit
Step11: Save the commit message and run push.
$ git push ssh://arnold.huang@xx.xx.xx.xxx:xxxxx/Automationxxxxxxxxxxxxxxxxxxx HEAD:refs/for/master
Enumerating objects: 54, done.
Counting objects: 100% (54/54), done.
Delta compression using up to 8 threads
Compressing objects: 100% (37/37), done.
Writing objects: 100% (40/40), 125.23 KiB | 2.28 MiB/s, done.
Total 40 (delta 19), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (19/19)
remote: Processing changes: refs: 1, new: 1, done
remote:
remote: SUCCESS
remote:
remote: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx Develop new Yocto smack function to cover smake [NEW]
remote:
To ssh://xxxxxxxxxxxxxxxxxxxxxxxx
* [new reference] HEAD -> refs/for/master
The git shows that a new review ticket is created. It's acceptable.
Step12: Let's reopen the webpage : http://xxxxxxxxxxxxxxxxxxxxxxxxxxx . You can see a chain is generated, this chain is acceptable. The first line ticket is created in order to fix the merge issue.
Step 13: Click the upper link , you can see only one "__init__.py" is pushed for review.
Step14: Call feature owner to review this ticket, passed by +1, automation team +2 in the newer ticket , then both can be merged.
Step 15: After the merging and submit, when you run "git pull origin master" in your branch or run "git pull" in your local master, you can see only one valid commit for this chain. The commit which has the merge conflict issue won't be shown in the git log.
$ git pull origin master
commit xxxxxxxxxxxxxxxxxxxx (HEAD -> myexample, origin/master, origin/HEAD)
Merge: 966a1b1 86b5129
Author: Arnold.Huang <Arnold.Huang@xxx.com>
Date: Thu Jul 22 08:53:08 2021 +0800
Develop new Yocto smack function to cover smake
Has fixed the conflict of __init__.py
Change-Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx