git 处理merge冲突


两处的代码git合并,需要解决产生的冲突,我现在初步接触merge的问题,暂且这样记录。

git pull遇到错误:error: Your local changes to the following files would be overwritten by merge:

  1. 保留原来的改动,先将远端代码pull下来然后应用原来的改动
    git stash
    git pull
    git stash pop
    
  2. 不保留原来的改动,直接回退到上一版本再pull
    git reset --hard
    git pull
    

fatal: refusing to merge unrelated histories

在操作命令后面加上--allow-unrelated-histories

Git『Everything up-to-date』问题解决

本来有要提交的代码但却说已经是最新版本了,解决方法是新建一个newbranch分支,将当前分支truebranch要提交的内容先提交到newbranch上,将新分支上的内容合并到truebranch上,再推truebranch的内容到远端仓库,最后删掉新分支。命令:

git branch
git branch newbranch
git branch
git checkout newbranch
git branch
git add .
git commit -m 'message'
git checkout truebranch
git merge newbranch
git diff
git push origin truebranch
git branch -D newbranch

新添的gitignore项在commit中生效

git rm -r --cached .
本文创建于2020-10-09 11:01,修改于2021年6月17日14点28分

原文地址:https://www.cnblogs.com/tellw/p/13784623.html