获取合并代码“正确”与Git [英] Getting merged code "right" with Git

查看:155
本文介绍了获取合并代码“正确”与Git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚合并了FETCH_HEAD并取得了我最近的更改,而不是他的覆盖了我的同事代码。我想在合并之前恢复,然后执行合并,迫使他在他触及文件的位置接受更改,但在没有任何其他更改的地方合并。

我的git日志(用l2 *创建)看起来像这样:

  * 3f6308d  - (HEAD,master)合并(Greyl b $ b | \ 
| * 283c00c - 更改要分隔的wv报告(仅限格式更改)(Sun Dec 29 09:07:27 2013)< Gre
| (thu Dec 26 19:39:
| |
| * 4846bf2 - 合并ssh://git-pacce@free1.projectlocker的分支'master'。 com / pcs.git(Wed Dec 25 17:49:19 2013)< jpjones>

当我执行了合并,这些文件中没有任何冲突,它只是采取了我的更改,而不是jpjones所做的不太新的更改。



基本上我想重做 3f6308d ,但允许jpjones更改s优先。 这个StackOverflow答案似乎与我想要达到的目标相关,但我不确定,希望澄清一些问题。

  * git l2 is alias l2 = log --graph --all --pretty = format:'%Cred%h %Creset  - %C(黄色)%d%Creset%s%Cgreen(%cd)%C(粗体蓝色)<%an>%Creset'--abbrev-commit --date = local 


解决方案

考虑到您还没有推送错误的提交,您可以安全地重置您的HEAD以前的提交:

  git reset --hard HEAD ^ 
HEAD ^
state)



这就是回答你提的建议。



但之后,你ne以确保您的同事在合并过程中采取了相应的更改,您将再次执行此操作。

查看 他们的合并策略选项的效果更好。

  git checkout yourBranch 
git merge -X他们他们的分支

然而,我怀疑它只会工作用于解决冲突(在文件中同时修改)。

如果您做出了更新的更改,那些更改仍然会出现在合并的HEAD中。



如果是这样,请尝试遵循此答案中的配方,强制合并到您的分支,然后重置 yourBranch theirBranch ,然后将HEAD移至之前完成的合并提交。

Then end result should看起来就像你在做什么。


I've just overwritten my co-workers code by merging FETCH_HEAD and getting my more recent changes instead of his. I want to revert to before the merge, then do the merge forcing his changes to be accepted where he touched the file, but getting my merges where there isn't any other changes.

My git log (created with l2*) looks like this now :

*    3f6308d - (HEAD, master) Merging changes (confliect in PriceListForm.java.. was a formatting change only (Sun Dec 29 09:07:27 2013) <Gre
|\  
| *  283c00c - Changing wv reports to be separated by changes in prices according to received_date rather than lab_number. (Thu Dec 26 19:39:
| |
| *  4846bf2 - Merge branch 'master' of ssh://git-pacce@free1.projectlocker.com/pcs.git (Wed Dec 25 17:49:19 2013) <jpjones>

When I performed the merge, there weren't any conflicts in those files, it just took my changes instead of the less recent changes by jpjones.

Basically I want to redo 3f6308d, but allow jpjones changes to take precedence. This StackOverflow Answer seems to be relevant to what I want to achieve, but I'm not sure and was hoping for some clarification.

* git l2 is alias l2 = log --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --date=local

解决方案

Considering you haven't pushed your faulty commit yet, you can safely reset your HEAD to the commit before:

git reset --hard HEAD^

(Make sure you don't have work in progress, like private files or files added to the index, because both the working tree and the index would be reset to the HEAD^ state)

This is what the answer you mention suggests.

But after that, you need to make sure your coworkers' changes are taken during the merge your are about to do again.
See if a theirs "merge strategy option" works better.

git checkout yourBranch
git merge -X theirs theirBranch

However, I suspect it would work only for solving conflicts (concurrent modifications in a file).
If you have made more recent changes, those would still be in the resulting merged HEAD.

If that is so, try following the recipe in this answer, which forces a merge to your branch, and then reset yourBranch to theirBranch, before moving HEAD to the merged commit done before.
Then end result should look like what you are after.

这篇关于获取合并代码“正确”与Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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