多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
一、stash them before you can merge. 解决办法 问题: 使用git pull更新代码的时候,遇到如下问题: $ git pull origin master From git.91als.net:root/yyg * branch master -> FETCH_HEAD Updating 09ee8ce..cd4108e error: Your local changes to the following files would be overwritten by merge: iad.html Please, commit your changes or stash them before you can merge. Aborting 出现这个问题,是由于其他人修改了***.html文件,然后提交到远程版本库咯。而你本地仓库也修改了***.html 思路1: 保留本地的修改 * git commit 把本地修改提交到版本库 $ git commit -m "add iad.html" On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean * git stash 将工作区恢复到上次提交之前,同时备份本地所做的修改 $ git stash Saved working directory and index state WIP on master: 09ee8ce add aa HEAD is now at 09ee8ce add aa (把本地的修改保存起来) lsf@lsf-PC MINGW32 /d/yyg/yyg (master) $ ll |grep iad.html (查看发现没有这个文件) * git pull 可以正常拉取代码咯 $ git pull origin master From git.91als.net:root/yyg * branch master -> FETCH_HEAD Updating 09ee8ce..cd4108e Fast-forward iad.html | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 iad.html * git stash pop: 从Git栈中读取最近一次保存的内容 $ git stash pop Auto-merging iad.html CONFLICT (add/add): Merge conflict in iad.html (这表示文件有冲突,我们就要解决冲突) <<<<<<< Updated upstream this isasfd weqr sdf ======= this is asdf sadfsadf weri >>>>>>> Stashed changes ~ (此时就需要协助,到底用谁的代码咯,然后添加到本地版本库,在提交到远程仓库) $ git add . lsf@lsf-PC MINGW32 /d/yyg/yyg (master) $ git commit -m "modify iad.html" [master 6d2dc0a] modify iad.html 1 file changed, 3 insertions(+), 3 deletions(-) lsf@lsf-PC MINGW32 /d/yyg/yyg (master) $ git push origin master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 278 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) To gitlab@git.91als.net:root/yyg.git cd4108e..6d2dc0a master -> master 最后 git stash clear: 清空Git栈 二、error: failed to push some refs $ git push origin master To git.91als.net:root/yyg.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'gitlab@git.91als.net:root/yyg.git' hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and 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. 解决: 我们需要先把远程版本库上的更新先pull到本地 $ git pull origin master From git.91als.net:root/yyg * branch master -> FETCH_HEAD Already up to date. 还有一种可能,是远程仓库有这个问题,发生了冲突,我们就需要看远程仓库里的这个文件,和本地的这个文件,然后做一个对比咯 三)error: failed to push some refs to '../remote/' 问题: $ git push To ../remote/ ! [rejected]        master -> master (non-fast-forward) error: failed to push some refs to '../remote/' 或者: $ git push origin master To git.91als.net:root/yyg.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'gitlab@git.91als.net:root/yyg.git' 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. 问题 (Non-fast-forward) 的出现原因在于: git remote 仓库中已经有一部分代码, 所以它不允许你直接把你的代码覆盖上去. 解决: 1)先fetch到本地 $ git fetch remote: Counting objects: 6, done. remote: Compressing objects: 100% (4/4), done. remote: Total 6 (delta 2), reused 0 (delta 0) Unpacking objects: 100% (6/6), done. From git.91als.net:root/yyg cd4108e..b095b9e master -> origin/master Administrator@WIN-0JU14CFTKDB MINGW32 ~/Desktop/yyg (master) 2)然后合并(发现有冲突) $ git merge Auto-merging test.html CONFLICT (add/add): Merge conflict in test.html Automatic merge failed; fix conflicts and then commit the result. Administrator@WIN-0JU14CFTKDB MINGW32 ~/Desktop/yyg (master|MERGING) $ vim test.html (解决冲突) 然后在通过git add,git commit 提交到本地版本库,然后push到远程仓库,发现可以咯 $ git commit [master 56caf41] Merge remote-tracking branch 'refs/remotes/origin/master' Administrator@WIN-0JU14CFTKDB MINGW32 ~/Desktop/yyg (master) $ git push origin master Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 565 bytes | 80.00 KiB/s, done. Total 6 (delta 2), reused 0 (delta 0) To git.91als.net:root/yyg.git b095b9e..56caf41 master -> master 四) $ git push test_dev fatal: 'test_dev' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 解决办法: $ git push origin test_dev Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 276 bytes | 69.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: remote: To create a merge request for test_dev, visit: remote: http://git.91als.net/root/yyg/merge_requests/new?merge_request%5Bsource_branch%5D=test_dev remote: To git.91als.net:root/yyg.git * [new branch] test_dev -> test_dev