相信很多同学在项目开发阶段,都会遇到Git冲突,项目参与人数越多发生的概率越大。

对于接触git不久的同学可能会盲目的百度:

Save your local code, return your local code version, and so on.

git reset --hard commitID

Someone will force the submission of code, maybe someone will force the get of code.

git push -u origin master -f OR git reset --hard  git pull

Anyway,我认为在团队合作期间代码发生冲突事件需要人工解决冲突代码,这一点应该是无法改变的。

如何快捷方便管理你的本地代码,在不被覆盖的情况下同步线上最新的代码与在本地合并后解决冲突再提交 ?

一、git stash [massage]            massage可选,为保存本地代码备注。

二、git pull                                    保存本地代码后进行pull

三、git stash list                            查看stash保存列表

四、git stash pop                        获取最新一次stash保存内容,恢复现场代码及修改。

五、手工解决冲突代码。

六、git add. git commit -m {}  git push                               

记得git stash drop stash id(list查看)或者 git stash clear删除所有存储。

以上是个人在遇到冲突后认为比较快速解决并不会覆盖本地代码的方式。

可以的话还是希望遵守Gitflow开发流程 ^ _ ^

如果有同学有更好的解决方法,欢迎留言。

study hard and make progress every day


Laurence
1 声望1 粉丝

swordsman @笑傲江湖