写在前面:
之前使用git工具整理代码时,太粗心大意了,踩了不少坑。在此想说我们遇到问题不要慌,其实认真看error、hint、fatal基本都能解决哒。
还有轻易莫rm,否则追悔莫及呀~~~~~~
会持续踩坑,持续更新这篇博客~~~~~~
$ 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
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
//这是强制提交本地代码,覆盖远程上的修改。这种方法同样慎用,除非你把远程仓库的修改代码复制到本地。