正确的方法来比较不同分支中的相同文件 [英] Correct way to compare same file in different branches

查看:103
本文介绍了正确的方法来比较不同分支中的相同文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题如何比较来自两个不同分支的文件? 处理在不同分支中比较相同文件的问题,但给出了几个答案,并且它们都似乎有一些警告。



这些是提供的方式:

pre $ g $ diff $ mybranch master - myfile.cs

(有些人抱怨这不适合他们;它确实适用于我的情况)

  2- git difftool branch1:文件branch2:文件

使用冒号不是一个好方法)

  3- git difftool branch1 branch2路径/到/文件

建议使用哪种方式?

解决方案


  • 您的选项1.和3.完全相同,除了事实在使用 - 时将它作为路径消歧。



    当路径当前不存在时,这可能很重要(在分支或本地)。

  • 现在,我不知道结肠符号有什么不好的地方。这是最通用的,因为你甚至可以做

    $ g $ diff $ git difftool branch1:file_name1.txt branch2:path / to / some_otherfilename.txt







<然后:

 如果只涉及打字(我猜这就是评论者所说的不太好 git difftool {branch1,branch2}:文件

甚至

  git difftool branch {1,2}:file 



在bash中会做得很好


This question How to compare files from two different branches? deals with the issue of comparing the same file in different branches, but several answers are given and all of them appear to have some caveat.

These are the ways presented:

1- git difftool mybranch master -- myfile.cs

(several people complain about this not working for them; it did in my case)

2- git difftool branch1:file branch2:file

(a comment says "Using the colons is not really a great way")

3- git difftool branch1 branch2 path/to/file

Which one is the recommended way?

解决方案

  • Your options 1. and 3. are exactly the same, apart from the fact that using -- disambiguates it as a path.

    This may be important when the path doesn't currently exist (in either branch or locally).

  • Now, I don't know what's so bad about the colon notation. It's the most versatile, because you can even do

    git difftool branch1:file_name1.txt branch2:path/to/some_otherfilename.txt
    


If it's just about the typing involved (I guess this is what the commenter means with "not great") then:

git difftool {branch1,branch2}:file

Or even

git difftool branch{1,2}:file

Would do nicely in bash

这篇关于正确的方法来比较不同分支中的相同文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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