快捷搜索: 王者荣耀 脱发

踩坑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 //这是强制提交本地代码,覆盖远程上的修改。这种方法同样慎用,除非你把远程仓库的修改代码复制到本地。
经验分享 程序员 微信小程序 职场和发展