git解决冲突 merge 不提示_使用git merge解决冲突的单独提交

I'm trying to merge a big topic branch into the master, but I want a separate commit that shows how the conflict resolution happened. The goal is to have one commit that shows "these files conflicted and how they conflicted" and the next commit would show "this is how the conflicts were resolved". I.e. the first commit would contain the conflict markers.

The reason for this is that the big topic branch has been reviewed and tested, as has the master branch. Of the merge, we want to review only the parts that needed some work (conflicts and other merge work).

Here's what I'm doing this far:

git checkout master

git checkout -b merge-from-topic

git merge topic

To record the files that have conflicts, I use a temporary file:

git diff --name-only --diff-filter=U >conflicts.txt

First I simply add those files, with the conflict markers, to a commit:

xargs git add

git commit

Then I create another branch (for review purposes) in which I'd like to do the conflict resolution:

git checkout -b resolve-merge-from-topic

To restore the conflicts, I tried

xargs git reset HEAD^ --

but then git mergetool said that none of the files need merging although files in my working tree had conflict markers.

How do I restore files listed in conflicts.txt, so that I can use git mergetool on them?

I'm also open to other ways of getting the "separate commit for conflict resolution" effect.

解决方案

git merge will leave conflict markers.

You then (usually) invoke git mergetool (with the --tool of your preference) to resolve the conflicts. Most of the time, this will result in staged changes. This you want to change (e.g. using git reset).

Now commit the 'raw' merge in isolation, and subsequently git add . && git commit -m 'resolutions' or git commit -am 'resolutions' to add the conflict resolutions.

Note this leaves you with a 'broken' build at the merge boundary revision.

In steps:

git checkout -b be_merged # start a temp branch for the merge (safety)

git merge --no-commit diverge # initiate merge from a diverged branch

git status # shows conflicts

git mergetool # resolve them as always

git status # shows resolutions as staged

git reset # unstage the changes

git status # shows unstaged changes (good!)

git commit -m 'merge, conflicts pending' # commit the merge

git commit -am 'conflicts resolved' # commit the resolutions

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值