[Git] pull branch error fatal: Need to specify how to reconcile divergent branches...


Example image of error message :

insert image description here
示例代码:
➜  fisher git:(test) git pull origin test
From git.woa.com:wxg-bigdata/fisher
 * branch              test       -> FETCH_HEAD
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.


Translation:
➜fisher git:(test) git pull origin test
from git.woa.com:wxg-bigdata/fisher*
branch test -> FETCH_HEAD
Hint: You have different branches and need to specify how to reconcile them.
Tip: You can do this by running one of the following commands sometime before Tip
: Your next move:
Tip:
Tip: git config pull.rebase false # Merge (default strategy)
Tip: git config pull. rebase true # Rebase
hint: git config pull.ff only # Fast-forward only
Hint:
Hint: You can replace "git config" with "git config --global" to set defaults
Hint: Prefer all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: call.
fatal: Need to specify how to coordinate different branches.


Solution
Analysis: This is because you have merged and updated the branch before pulling the pull branch, and others have pushed a version before you, resulting in inconsistent versions

The first solution: relatively simple

Executing git config pull.rebase false
will merge the pulled code with the existing changed code by default,
but it may cause code conflicts. This problem needs to be dealt with. If two people have changed the same file, you need to contact the push before Classmates, let’s see how to save this piece of code
. The second solution: roll back to the code before the merge, and pull the latest code after pulling

Note: This solution is only applicable to the merge (git merge) operation between two branches. For example, if you did not pull before merging the dev development branch into the test branch, then the test branch needs to roll back to the one before the merge. Version.
The merged code on test will be lost. After your test branch can be successfully pulled, you need to re-merge (merge) the code on the development branch dev and merge it into test. So remember to keep the code of this version of the dev development branch, then roll back the test to the previous version, wait for the pull to succeed, and then re-merge the code of the dev branch on the test branch

View the historical versions of the last 3 submissions
➜ fisher git:(test) git log -3 # View the historical versions of the last 3 submissions
commit da20b931f4e04a61f0f9b4e4726a2e907e566fc9 (HEAD -> test)
Merge: 33df706e 6018c237
Author: Meteor
Date: Wed Jan 19 09: 58:40 2022 +0800

    Merge branch 'feture/tapd#870810123' into test

commit 6018c237278f5265e78314049d6642e493ebdb5e (feture/tapd#870810123)
Author: 流星
Date:   Wed Jan 19 09:57:50 2022 +0800

    feat: release version 'feture/tapd#870810123'

commit 33df706e780d10af6435bda1fee85430604eebfc
Merge: 1d06cd1f 7589979d
Author: 流星
Date:   Tue Jan 18 16:11:21 2022 +0800

    Merge branch 'feature/date#0118' into test


According to the historical version records, select the commit address and roll back to the version before the merge
➜ fisher git:(test) git reset --hard 33df706e780d10af6435bda1fee85430604eebfc
HEAD is now at 33df706e Merge branch 'feature/date#0118' into test
1
2
and then proceed Pull update branch
➜ fisher git:(test) git pull origin test
1
Finally re-merge the code
➜ fisher git:(test) git merge dev
1
Remember to develop a good habit of git release process

# Branch merge release process:
git add . # Add all new, modified or deleted files to the temporary storage area
git commit -m "version release" # Release the files in the temporary storage area
git status # Check if there are any files Not published
git checkout test # Switch to the branch to be merged
git pull # Pull the latest code on the test branch to avoid conflicts
git merge dev # Merge the code on the dev branch on the test branch
git push # Upload the test branch code

Guess you like

Origin blog.csdn.net/kuang_nu/article/details/129586010