git rebasing很多提交时如何防止大量的git冲突? [英] How to prevent lot of git conflicts when git rebasing lot of commits?

查看:290
本文介绍了git rebasing很多提交时如何防止大量的git冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

故事:在一个项目的中间,我的同事从 master 创建了一个新分支,并开始进行大量的重新分解工作。我从 master 创建了我的分支,并开始在页面上做新东西。我们经常提交,但只能将代码重新分配给 master (因为同事的更改过于繁重,无法从主服务器部署)。不幸的是我们的一些工作依赖于相同的文件。因此,经过几天的工作,当她终于想要改变她对 master 的更改时,她有很多git冲突。

  my_branch#---#----# - #-------#----# - #-----#---#----#----#
/ \\\\\\\\\\\\\\\\\\\\ $ --- * -------------- * --- * --- * -------------- * ---- * --- - *
\ /
她的分支#------#-------#-----------#------- ----#------------#

问题1是:当我们处理相同的文件时,如何防止大量的git冲突? (或者这种情况下的最佳做法是什么?)



但这不是我们问题的结尾,...要绝对正确的,她试图从主人到她的分支进行rebase(为了改变我犯下的错误),所以commit map应该看起来像这样

  my_branch#---#----# - #-------#----# - #-----#---#----#--- - #
/ \ \ \\\\
master * ------- * -------------- * - - * --- * -------------- * ---- * ---- *
\\\\\
她的分支# - -----#-------#---- * ------#----- ----- *#------------ #

这就是困扰我们的原因。在这些重组期间,她正在修复这些冲突。但git不记得她在冲突修复上的决定,所以当她从 master her-branch 完成另一个git rebase时,她必须修复相同的git冲突



问题2 :如何告诉git在git之后记住git冲突修复我们不必再次修复相同的冲突?

幸运的是,git有一个处理这个问题的机制,叫做 git rerere - 实际上,如果你有 git rerere 已启用,那么每次解决冲突时,都会记住您以特定方式解决了确切冲突的事实。如果再次出现相同的冲突,则会自动使用相同的分辨率。以下是一些有用的文章:



...但基本上你可以这样做:

  git config --global rerere.enabled 1 

...忘记它,同时享受更轻松的重新绑定/合并:)


Story: in the middle of a project my colleague created a new branch from master and started doing her heavy re-factoring work. I created my branch from master and started doing new stuff on the page. We are committing regularly, but only I can rebase code to master (because colleagues changes are too heavy and cannot be deployed from master yet). Unfortunately some of our work rely on the same files. So after few days of work when she finally wanted to rebase her changes to master, she had a lot of git conflicts.

my_branch    #---#----#-#-------#----#--#-----#---#----#----#
            /     \              \   \   \              \    \
master     *-------*--------------*---*---*--------------*----*----*
            \                                                     /
her branch   #------#-------#-----------#-----------#------------#

Question 1 is: how to prevent lot of git conflicts when we are working on same files? (or what is the best practice in this situation?)

but this isn't the end of our question, ...to be absolutely correct she tried to do rebase from master to her branch (to have changes I committed), so the commit map should look something like this

my_branch    #---#----#-#-------#----#--#-----#---#----#----#
            /     \              \   \   \              \    \
master     *-------*--------------*---*---*--------------*----*----*
            \                   \            \                    /
her branch   #------#-------#----*------#-----*-----#------------#

And this is what is bothering us. During these rebases she was fixing those conflicts. But git doesn't remember her decision on conflict fix, so when she did another git rebase from master to her-branch she had to fix the same git conflicts again that she was fixing in previous rebases.

Question 2 is: how to tell git to remember git conflict fix after git rebase from master branch, so after next rebase we don't have to fix the same conflicts again?

解决方案

Fortunately, git has a mechanism for dealing with exactly this problem called git rerere - essentially, if you have git rerere enabled, then each time your resolve a conflict the fact that you resolved that exact conflict in a particular way is remembered. If the same conflict comes up again, the same resolution is automatically used. There are some helpful articles below:

... but essentially you can just do:

git config --global rerere.enabled 1

... and forget about it, while enjoying easier rebasing / merging :)

这篇关于git rebasing很多提交时如何防止大量的git冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆