美文网首页
【CMD|GIT】本地代码和远程代码产生冲突(二)

【CMD|GIT】本地代码和远程代码产生冲突(二)

作者: 盐果儿 | 来源:发表于2024-01-01 05:29 被阅读0次

Error: 

! [rejected] main -> main (fetch first)

error: failed to push some refs to 'https://github.com/Annedrew/Scripts.git'

hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushing

hint: to the same ref. You may want to first integrate the remote changes

hint: (e.g., 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.


Solution :

1. Start by fetching the changes from the remote repository, and merge it into local repository.

git fetch origin main

git merge origin main

2. Open the files that have conflicts in a text editor, and locate the conflicting sections in the file, such as:

<<<<<<< HEAD

Your changes

=======

Remote changes

>>>>>>> branch-name

3. Resolving the conflicts, save the file.

4. Add the resolved files to the staging area.

git add <file name>

5. Commit the changes to complete the merge. 

(If there are multiple conflicted files, repeat steps 2-5 for each file.)

git commit -m "merge remote changes"

6. Push your changes to the remote repository.

git push origin <branch-name>


相关文章

  • 实习笔记4

    git 远程代码更新到本地 安全流程 git status(查看本地分支文件信息,确保更新时不产生冲突) git ...

  • git用命令行提交代码及解决冲突

    git pull, 提交之前先拉取远程代码, 如果在本地代码与远程代码有冲突, 会有CONFLICT, 拉取失败 ...

  • git 总结

    参考资料:git 删除本地分支和远程分支、本地代码回滚和远程代码库回滚 git 删除分支 1. 本地分支:git ...

  • git 基础

    git基础用法 可更新远程develop最新代码 避免或减少代码合并冲突 1自己本地开发分支 git stash ...

  • git篇之pull

    拉取远程代码git pull git pull //从远程主分支拉取最新的代码 自动merge所以可能会产生冲突 ...

  • git pull操作的时候,提示有冲突

    问题 当本地代码和远程代码有冲突的时候,执行git pull操作的时候,会提示有冲突,然后直接终止本次pull. ...

  • Git语法管理

    一:基础语法 二:高级语法 使远程库强制覆盖本地代码(git pull时出现冲突 放弃本地修改) 本地版本强制覆盖...

  • Git: pull时提示Please commit your c

    对本地的代码进行修改后,直接git pull会提示本地代码和github代码冲突,需要先commit本地代码,或者...

  • 2018-08-15 git冲突

    1、git pull时出现冲突方法一:放弃本地修改,使远程库内容强制覆盖本地代码 方法二:reset1、只能往前面...

  • git常用指令

    下载远程仓库代码 git clone 代码仓库地址 从远程仓库拉取代码 git pull 提交代码到本地分支,并推...

网友评论

      本文标题:【CMD|GIT】本地代码和远程代码产生冲突(二)

      本文链接:https://www.haomeiwen.com/subject/jjfundtx.html