在git合并冲突中,我如何保留被合并的版本? [英] In git merge conflicts, how do I keep the version that is being merged in?

查看:1022
本文介绍了在git合并冲突中,我如何保留被合并的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器上有两个本地git分支 - 名为v2的分支和名为master的分支。我将v2合并到master,而master被签出并且分支。



我想将v2分支合并到master分支中。当我执行合并时,我必须逐一解决一些冲突。



对于每次冲突,我如何保留v2分支文件和而不是文件的master分支版本?



Git Tower为这些类型的冲突呈现给我的选项是:


  • 将FILENAME标记为手动解决
  • 通过保留FILENAME进行解析

  • 通过删除FILENAME进行解析
  • li>
  • 恢复他们的FILENAME版本

  • 在外部应用程序中打开

  • 根据我的理解,保留文件选项意味着保留v2版本(合并的文件)和删除文件,意味着不添加v2版本(但保留现有的主 版本)。但是,当我使用删除选项时,它实际上从回购库中完全删除了该文件。

    如何保留v2分支文件而不是master分支版本的文件对于这些类型的冲突是什么?

    解决方案

即使您正在使用Git Tower ,你可以下载到命令行并使用

  git checkout  - 他们的文件.txt 

这里有一些关于它的文档:

http://gitready.com/advanced/2009/02/25/ keep-either-file-in-merge-conflicts.html



如果您只想使用git tower,请按原样完成合并,然后签出该文件的其他分支的版本。如果可能的话,现在登台并提交修改



Git已经发展成为命令行工具。对于我曾经使用的其他工具,我总是在功能上存在差距。我选择了拥抱,而不是争取Git的设计。

另外,您可以勾选Beyond Compare之类的东西,并选择外部工具,就像您在问题中提到的那样。在那里,您可以选择他们的一面。


I have two local git branches on my machine - a branch called "v2" and a branch called "master". I'm merging v2 into master while master is checked out and the head branch.

I'd like to merge the "v2" branch into the "master" branch. When I perform the merge, there are a number of conflicts that I must resolve one by one.

For each conflict, how do I keep the "v2" branch file and not the "master" branch version of the file?

The options presented to me by Git Tower for these types of conflicts are:

  • Mark FILENAME as Manually Resolved
  • Resolve by Keeping FILENAME
  • Resolve by Deleting FILENAME
  • Restore Their Version of FILENAME
  • Open in External App

From my understanding, the option to "keep" the file meant keeping the "v2" version (the one being merged in) and "deleting" the file meant not adding the "v2" version (but instead keeping the existing "master" version). When I used the delete option, though, it actually deleted the file altogether from the repo.

How do I keep the "v2" branch file and not the "master" branch version of the file for these types of conflicts?

解决方案

Even though you are using Git Tower, you can drop down to the command line and use

git checkout --theirs file.txt

Here some docs about it:

http://gitready.com/advanced/2009/02/25/keep-either-file-in-merge-conflicts.html

If you want to ONLY use git tower, complete the merge as is, then checkout the other branch's version of that file. Now stage and commit with amend - if possible.

Git has been developed to be a command line tool. With every other tooling that I've ever used, I always had a gap in functionality. I chose to embrace instead of fight the design of Git.

Also, you could hook up something like Beyond Compare and choose "external tool" as is mentioned in your question. There, you will have an option to choose the "theirs" side.

这篇关于在git合并冲突中,我如何保留被合并的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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