● Phenomenon I get an error and can't push
● Error details error: failed to push some refs to "~~"
● What is the cause? Since the conflict was fixed on git lab, There is a difference between the commit history on the remote and the commit history on the local, causing an error.
The situation is as follows.
■ Local Commit history B (review corrections) Commit history 3 Commit history 2 Commit history 1
■ Remote Commit history A (conflict resolution) Commit history 3 Commit history 2 Commit history 1
● What should I do?
This time, I solved it by the following procedure. (1) Copy the local [sample_branch] that has been modified and create [sample_branch_copy] ② Delete the local [sample_branch] (3) Reflect [sample_branch] on the remote locally (acquire commit history A that resolves conflicts) ④ Extract the correction work from the copied [sample_branch_copy] ⑤ The extracted work contents are additionally reflected in the newly reflected local [sample_branch]. ⑥ Commit and push [sample_branch] again
● Operation commands
git branch sample_branch_copy
#Make a copy
git branch -d sample_branch
#Delete local branch
git fetch
#Reflect remote branch locally(Remote sample_Get branch)
Branch name: sample_branch_copy
git reset --soft HEAD^
#Uncommit and return to working state(Canceling a straight line commit)
git stash
#Take out the modified work
Branch name: sample_branch
git stash pop
#Reflect the corrected work contents
git branch
git log
#Always check the status of branch commands with the above command
● To prevent future errors,
In this case, it happened because I fixed the conflict on git lab. Therefore, it is possible to avoid it by fixing the conflict locally in the future.
Recommended Posts