此问题已从另一个角度here得到了回答。但是我的问题是要试图了解为什么首先会出现此问题。我一直在工作中遇到此问题,建议的解决方案并不能太令人满意,因为它不能真正解决问题本身,而且存在丢失提交的危险。
下面您会发现我发现的最短git交互序列,可重现该错误:
git clone [email protected]:joyofdata/test3.git
cd test3
echo "1" > m
git add .
git commit -m "m1"
git push origin master
git checkout -b feature
git push -u origin feature
echo "1" > f
git add .
git commit -m "f1"
git rebase master
git push origin feature
git checkout master
echo "2" >> m
git add .
git commit -m "m2"
git push origin master
git checkout feature
echo "2" >> f
git add .
git commit -m "f2"
git rebase master
git push origin feature (error - see next code box)
我只是简单地将master中的文件m版本,然后将特征f中的文件版本,然后在master中进行更改,然后在feature中进行更改。现在,在将更改推送到远程功能分支之前,我想将其重新基于master。
这是命令和上面列表中最后一个命令的错误消息:
➜ test3 git:(feature) git push origin feature
To github.com:joyofdata/test3.git
! [rejected] feature -> feature (non-fast-forward)
error: failed to push some refs to '[email protected]:joyofdata/test3.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
现在-我尝试通过首先从远程功能中拉出来解决此问题(如消息中所建议),然后解决冲突,并推送至功能:
➜ test3 git:(feature) git pull origin feature
From github.com:joyofdata/test3
* branch feature -> FETCH_HEAD
Auto-merging f
CONFLICT (add/add): Merge conflict in f
Automatic merge failed; fix conflicts and then commit the result.
➜ test3 git:(feature) ✗ vim f
➜ test3 git:(feature) ✗ git add .
➜ test3 git:(feature) git commit -m "deconflicted"
[feature 3fb647e] deconflicted
➜ test3 git:(feature) git push origin
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 565 bytes | 565.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To github.com:joyofdata/test3.git
0f31f60..3fb647e feature -> feature
但是-从现在开始-每次我基于master重新设置功能时,我都会一次又一次地遇到该错误-再次发生合并冲突,并且再次发生该错误。
➜ test3 git:(feature) git rebase master
First, rewinding head to replay your work on top of it...
Applying: f1
Applying: f1
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: f2
➜ test3 git:(feature) git push origin
To github.com:joyofdata/test3.git
! [rejected] feature -> feature (non-fast-forward)
error: failed to push some refs to '[email protected]:joyofdata/test3.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我不明白!
我的意思是-我想做的就是简单地应用以下工作流程:
我很简单-在提交对远程功能的提交之前,我想基于master重新设置功能。如果我将母版合并到功能中(如果本地母版是最新的,则合并为git pull origin master
或git merge master
),那么我就不会遇到该问题。
我希望这不会太令人困惑,但我不知道如何简化它,这真的让我很烦。
这里已经从另一个角度回答了这个问题。但是我的问题是要试图了解为什么首先会出现此问题。我一直在工作中遇到此问题,并且...
快速的答案是不要为上游分支建立基准,此链接说明了问题和解决方案:https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase
问题的根源在于您正在重新建立feature
。这是一种草率的表达方式:无关紧要的是[[branch name