当我第二次推送功能分支时,如何避免收到以下消息:
To https://github.com/xxx/git_test.git
! [rejected] feature_branch -> feature_branch (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx/git_test.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我要做的是:
git pull origin sprint_branch1
git checkout -b feature_branch
date > a.txt
git add a.txt
git commit -m 'added date'
git push origin feature_branch
有人对我的功能进行代码审查,同时其他人对 sprint_branch 进行更改:
git checkout sprint_branch1
date > a.txt
git add a.txt
git commit -m 'added another date'
git push origin sprint_branch1
我需要改进我的功能,所以我这样做
git checkout feature_branch
git fetch origin
git rebase origin/sprint_branch1
我遇到合并冲突并执行以下操作:
nano a.txt # removing inserted merge tags
git add a.txt
git rebase --continue
然后我改进我的功能
date >> a.txt
git add a.txt
git commit -m 'add another date again'
我喜欢推送我的 feature_branch 进行第二次审查
git push origin feature_branch
但是,我收到顶部提到的错误消息。Git 建议我使用 git pull,但其他人建议我使用 rebase 工作流程。那么我应该怎么做才能推送 feature_branch 呢?我应该创建一个名为 feature_branch_v2 的新分支并推送它吗?在这种情况下,我是否需要手动记住要 git add 的文件,还是应该添加所有文件(创建一个混乱的提交)?有没有更好的推送方法而不会收到此错误消息?