`
wbj0110
  • 浏览: 1586299 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

Git错误non-fast-forward后的冲突解决

阅读更多

当要push代码到git时,出现提示:

error:failed to push some refs to ...

Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:

  1. $ git push origin master  
  2. To ../remote/  
  3.  ! [rejected]        master -> master (non-fast forward)  
  4. error: failed to push some refs to '../remote/'  

To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast forward'
section of 'git push --help' for details.
This error can be a bit overwhelming at first, do not fear. Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.
In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase. While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.

 

问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:

1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容

git push -f

2,先把git的东西fetch到你本地然后merge后再push

$ git fetch

$ git merge

这2句命令等价于

  1. $ git pull  

可是,这时候又出现了如下的问题:

 

上面出现的 [branch "master"]是需要明确(.git/config)如下的内容
[branch "master"]
    remote = origin

    merge = refs/heads/master

这等于告诉git2件事:

1,当你处于master branch, 默认的remote就是origin。

2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是origin)来merge在master branch上所有的改变

如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行:

  1. $ git config branch.master.remote origin  
  2. $ git config branch.master.merge refs/heads/master  

之后再重新git pull下。最后git push你的代码吧。it works now~

分享到:
评论

相关推荐

    Git-2.13.2-64-bit

    解决冲突需要手动编辑冲突文件,标记出哪些是冲突区域,然后提交解决后的版本。 9. **Git的持续集成/持续部署(CI/CD)**: - Git可以与持续集成服务(如Jenkins、Travis CI)集成,自动构建和测试代码,甚至部署到...

    Git-2.15.0-64-bit.exe

    同时,`git merge`也得到了增强,提高了合并冲突解决的效率。 3. **更好的克隆体验**:Git 2.15引入了`--mirror`选项的改进,克隆时可以更有效地复制远程仓库的完整状态,这对于镜像仓库特别有用。 4. **增强的GUI...

    git安装包git-2.34.0-64-bit.rar

    用户需要手动编辑冲突文件,解决冲突后提交更改。 7. **远程仓库**:Git可以与像GitHub或GitLab这样的远程服务集成,`git remote add origin`命令用于添加远程仓库,`git push -u origin main`将本地分支推送到远程...

    Git-2.28.0-64-bit.exeGit-2.28.0-64-bit.exe

    Git-2.28.0-64-bit.exe Git-2.28.0-64-bit.exe Git-2.28.0-64-bit.exe

    git-2.15.0-intel-universal-mavericks.dmg.zip

    2. **增强的合并工具**:Git可能更新了内置的合并工具,提供更好的冲突解决体验,使用户更容易理解并解决代码合并中的冲突。 3. **更友好的用户界面**:可能改进了命令行界面,增加了新的命令或选项,使得日常操作...

    windows xp Git32 安装包 Git-2.10.0-32-bit

    6. **强大的冲突解决**:Git在合并代码时,如果出现冲突,会清晰地标记出冲突位置,帮助开发者解决。 7. **插件支持**:Git社区提供了许多插件,可以扩展Git的功能,例如git-flow用于支持Gitflow工作流,SourceTree...

    Git官方最新版下载 Git-2.18.0-64-bit 64位Windows版本

    Git-2.18.0-64-bit是Git官方发布的一个针对64位Windows系统的更新版本,旨在提供更稳定、高效和功能丰富的代码管理体验。 1. Git的基本概念: - 版本控制:Git的核心功能是版本控制,它记录了代码的每一次修改,...

    Git-2.28.0-64-bit git安装包windos64位官方下载

    Git-2.28.0-64-bit.exe 是适用于Windows 64位操作系统的Git官方安装程序,该版本为2.28.0,意味着它包含了最新的功能和性能改进。 **Git基础概念** 1. **版本控制**:Git的核心功能是版本控制,它能跟踪文件和目录...

    Git-2.23.0-64-bit.zip

    安装“Git-2.23.0-64-bit.exe”后,用户将获得一个完整的Git环境,包括Git命令行工具、图形界面工具(如Git Bash和Git GUI),以及用于Windows集成的shell扩展。这使得在Windows操作系统上管理和协作代码变得更加...

    git-2.41.0-64-bit window版本

    3. 错误修复:解决了之前版本中发现的问题,提高了软件的稳定性。 4. 用户界面改进:可能改善了图形界面工具(如Git GUI或GitKraken)的用户体验。 5. 兼容性增强:可能增强了与其他工具或服务(如GitHub、GitLab)...

    git-2.45.0-64bit.exe

    "git-2.45.0-64bit.exe" 是Git的特定版本,即2.45.0版本的64位Windows安装程序。这个文件是为Windows用户设计的,确保在64位操作系统上顺利运行Git。 Git的核心特性包括: 1. 分布式:每个开发者的本地仓库都包含...

    Git-2.21.0-64-bit.zip

    7. 合并冲突解决:Git在合并分支时可能会遇到冲突,它提供了一套解决冲突的机制,帮助用户分析和解决代码差异。 总之,Git-2.21.0-64-bit.zip包含了在Windows 64位环境下使用Git所需的所有组件,让用户能够充分利用...

    Git安装包 Git-2.15.1.2-64-bit和Git-2.15.1.2-32-bit以及常用命令行PDF

    8. **解决冲突**:当多个用户修改了同一部分代码时,Git会报告冲突,需要手动编辑冲突文件并重新提交。 Git-cheatsheet.PDF通常包含更全面的Git命令和操作流程,可以帮助用户快速查找和学习Git命令。它可能包括高级...

    Git-2.12.0-64-bit 64位下载

    Git-2.12.0-64-bit 64位下载

    Git-2.34.0-64-bit安装包

    Git-2.34.0-64-bit安装包

    Git-2.6.4-64-bit

    Git-2.6.4-64-bit,windows版本

    Git-2.28.0-64-bit.exe.zip

    在这个"Git-2.28.0-64-bit.exe.zip"压缩包中,包含的是Git的最新Windows版安装程序,适用于64位操作系统。这个版本是2.28.0,它在Git的历史中扮演着重要的角色,因为每个新版本都带来了性能优化和新功能。 Git的...

    Git-2.26.0-64-32.zip

    这个压缩包"Git-2.26.0-64-32.zip"包含了适用于不同系统架构的安装程序,分别是"Git-2.26.0-64-bit.exe"和"Git-2.26.0-32-bit.exe"。 Git的核心特性包括: 1. 分布式:每个开发者的本地机器上都有一个完整的版本库...

    Git-2.25.1-64-bit.rar

    Git-2.25.1-64-bit.rar是一个包含Git 2.25.1版本的64位安装程序的压缩包,专为Windows操作系统设计。这个版本在2020年初发布,提供了一些新的特性和改进,对于Windows用户来说,是一个重要的更新。 Git的主要功能...

    Git-2.32.0-64-bit.rar

    这个压缩包"Git-2.32.0-64-bit.rar"包含了Git的最新稳定版,适用于64位Windows系统,并且直接来源于Git官方网站,确保了软件的安全性和完整性。 Git的核心特性包括: 1. 分布式:每个开发者的本地仓库都是完整的...

Global site tag (gtag.js) - Google Analytics