我是一个相当新的人,git目前正在使用它来管理团队环境中的代码.我有一些变基础问题,我用它来修复它们
git checkout --ours filename.txt
git add filename.txt
git rebase --continue
Run Code Online (Sandbox Code Playgroud)
现在我想推送我的更改,然后运行以下命令
$ git push origin feature/my_feature_branch
Run Code Online (Sandbox Code Playgroud)
给我以下错误:
To ssh://git@coderepo.com:7999/repo/myproject.git
! [rejected] feature/my_feature_branch -> feature/my_feature_branch (non-fast-forward)
error: failed to push some refs to 'ssh://git@coderepo.com:7999/repo/myproject.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.
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能摆脱这个错误?
PS:我--force尽量避免使用该选项.
Bor*_*ski 61
看起来,有人推动了你的最后一次git fetch和之间的新提交git push.在这种情况下,您需要重复您的步骤并再次使用rebase my_feature_branch.
git fetch
git rebase feature/my_feature_branch
git push origin feature/my_feature_branch
Run Code Online (Sandbox Code Playgroud)
之后,git fetch我建议检查情况gitk --all.
Eng*_*eer 21
可能你没有在rebase之前获取远程更改,或者有人推送了新的更改(当你进行变基和尝试推送时).请尝试以下步骤:
#fetching remote 'feature/my_feature_branch' branch to the 'tmp' local branch
git fetch origin feature/my_feature_branch:tmp
#rebasing on local 'tmp' branch
git rebase tmp
#pushing local changes to the remote
git push origin HEAD:feature/my_feature_branch
#removing temporary created 'tmp' branch
git branch -D tmp
Run Code Online (Sandbox Code Playgroud)
Bil*_*lal 14
我迟到了,但我在github 帮助页面中找到了一些有用的说明,我想在这里分享它们。
有时,Git 无法在不丢失提交的情况下对远程存储库进行更改。发生这种情况时,您的推送将被拒绝。
如果其他人已推送到与您相同的分支,Git 将无法推送您的更改:
$ git push origin master
To https://github.com/USERNAME/REPOSITORY.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/USERNAME/REPOSITORY.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)
您可以通过获取远程分支上所做的更改并将其与您在本地所做的更改合并来解决此问题:
$ git fetch origin
# Fetches updates made to an online repository
$ git merge origin YOUR_BRANCH_NAME
# Merges updates made online with your local work
Run Code Online (Sandbox Code Playgroud)
或者,您可以简单地用于git pull同时执行两个命令:
$ git pull origin YOUR_BRANCH_NAME
# Grabs online updates and merges them with your local work
Run Code Online (Sandbox Code Playgroud)
小智 12
我有这个问题!我试过了:git fetch + git merge,但没解决!我试过了:git pull,也没解决
然后我尝试了这个并解决了我的问题(类似于工程师的回答):
git fetch origin master:tmp
git rebase tmp
git push origin HEAD:master
git branch -D tmp
Run Code Online (Sandbox Code Playgroud)
小智 8
试试这个命令
$ git push -f -u origin <name of branch>
IE $ git push -f -u origin master
出现非快进错误后,只需执行以下操作:
1> git pull --rebase origin <name-of-the-remote-branch>
这会将远程更改获取到本地分支。最重要的是,它将应用您的本地提交。
2> git push origin <name-of-the-remote-branch>
这会将远程分支本地副本中的本地更改应用到 git 中的实际远程分支存储库
| 归档时间: |
|
| 查看次数: |
189332 次 |
| 最近记录: |