Git pull 冲突解决(正解)

1. 问题描述:

王修改了文件A并且push到了git server上,这时李也在修改文件A,但修改没有完成,李希望获得最新的代码,如果李直接pull的话会遇到一下问题:

error: Your local changes to the following files would be overwritten by merge:

***************************************

Please, commit your changes or stash them before you can merge.


造成冲突的原因:

很多命令都可能出现冲突,但从根本上来讲,都是merge 和 patch(应用补丁)时产生冲突。
而rebase就是重新设置基准,然后应用补丁的过程,所以也会冲突。
git pull会自动merge,repo sync会自动rebase,所以git pull和repo sync也会产生冲突。当然git rebase就更不用说了。


2. 问题解决

2.1 commit your change

先提交你的改动,在更新代码


2.2 stash

git stash

git pull

git stash pop

git stash的作用是把本地的改动保存起来,、

然后在git pull 这样就不会有冲突的问题

最后git stash pop 就是把之前的改动merge到代码中。


2.3 merge

使用git merge --abort中止merge。merge manual中说,这条命令会尽力恢复到Merge之前的状态(可能失败!)。

merge manual中有一条警告:

Warning: Running git merge with uncommitted changes is discouraged: while possible, it leaves you in a state that is hard to back out of in the case of a conflict.


3. 参考文献

[1] http://www.cnblogs.com/sinojelly/archive/2011/08/07/2130172.html

[2] http://blog.csdn.net/iefreer/article/details/7679631

猜你喜欢

转载自blog.csdn.net/xuzhenmao_soft/article/details/80314853
今日推荐