Git冲突处理的一些经验

来源:互联网 发布:搜狗拼音打字软件 编辑:程序博客网 时间:2024/05/20 04:51

1、git pull 冲突

问题

今天在web服务器上修改了一下代码配置项,后来进行git pull操作的时候,提示:

error: Your local changes to the following files would be overwritten by merge:        protected/config/main.phpPlease, commit your changes or stash them before you can merge.

解决方法

1、保留web服务器上的改动,仅仅合并git服务器上的新配置项,则需要

git stash
git pull
git stash pop
git diff -w +文件名      //确认代码自动合并的情况.

2、用git服务器上的文件完全覆盖web服务器上的文件,则

git reset --hard
git pull

注意:

push之后若需要返回之前版本,可以通过使用 git reset --hard <commit ID号> 或者 git reset --hard HEAD^来进行回退

2、git push 冲突

问题

本地执行git push origin master的时候,提示:

 ! [rejected]        master -> master (fetch first)error: failed to push some refs to 'http://xx.xx.xx.xx/xxx/xx.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决方法

该问题发生时由于在自己提交之前,已经有其他人提交过更新。此时解决的方法有两种:

1、git fetch

git fetch 命令会从远程获取最新版本到本地,然后我们可以手动合并

//获取最新版本

git fetch origin master:tmp

//比较本地和远程的差别

git diff tmp

//进行合并

git merge tmp


2、git pull

git pull 命令是从远程获取最新版本并会自动合并,执行

git pull origin master


0 0