踩坑git提交中的冲突解决

写在前面

之前使用git工具整理代码时,太粗心大意了,踩了不少坑。在此想说我们遇到问题不要慌,其实认真看error、hint、fatal基本都能解决哒。

还有轻易莫rm,否则追悔莫及呀~~~~~~

会持续踩坑,持续更新这篇博客~~~~~~


一.git pull线上代码时出现error: You have not concluded your merge,原因是在拉取时代码还没有合并

$ git pull
error: You have not concluded your merge (MERGE_HEAD exists).
hint: Please, commit your changes before merging.
fatal: Exiting because of unfinished merge.
解决方式有如下两种:

1.保留本地的修改

git merge --abort

git reset --merge

合并后要提交这个本地的合并,add->commit->push,然后获取远端仓库->pull

2.下载线上代码版本,放弃本地修改(慎用)

git fetch --all

git reset --hard origin/master

git fetch

二. git push的时候出现下面的错误:

hint: Updates were rejected because the remote contains work that you do
hint: 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.

解决方式如下:

git push -u 代码所在的分支 -f 

//这是强制提交本地代码,覆盖远程上的修改。这种方法同样慎用,除非你把远程仓库的修改代码复制到本地。

三.当提交代码发生冲突或者想要回退到某一历史版本,可以使用本地回退历史版本操作:

1. 获取提交的日志

git log 

2.本地回退历史版本

git reset --hard 版本号   //版本号即为上图commit后面的哈希值

3.此时若要修改远端仓库,则要强制push代码:

git push -u 代码所在的分支 -f    

//这是强制提交本地代码,覆盖远程上的修改。这种方法同样慎用,除非你把远程仓库的修改代码复制到本地。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值