比较GIT上2个不同分支上的2个文件

时间:2016-07-03 07:31:13

标签: git windows-8.1

我必须比较GIT上2个不同分支上的2个文件。之后我需要将它合并到master。

我看到了这个:

git diff branch1:full/path/to/foo.txt branch2:full/path/to/foo-another.txt

你能告诉我如何填写完整路径和branch1和branch2吗?

更新:我试过这样。但是它没有用。你能告诉我为什么吗?

git diff 
master:https://github.com/MyGit/blob/master/My.Web/App/tenant/views/propertymana
gement/index.less access-ui:https://github.com/MyGit/blob/access-
ui/My.Web/App/tenant/views/propertymanagement/index.less

以上命令提供错误

fatal: Path 'https://github.com/MyGit/blob/master/My.Web/App/t
enant/views/propertymanagement/index.less' does not exist in 'master'

3 个答案:

答案 0 :(得分:1)

  

你能告诉我如何填写完整路径和branch1和branch2吗?

它是工作树中当前路径的相对路径,而不是文件的URI。

对于具有两个文件夹dir1和dir2的本地工作树,您现在位于dir1并想要比较dir1中的文件,请使用以下命令:

while(1){

    while(!h_in) wait(h_in.posedge_event());    

    k = 0;

    for(i=0; i<3; i++){
        for(j=0; j<720; j++){
            image_buffer.pixel[i*image_buffer.width+j] = p_in;
            wait();
            while(!h_in) wait();

            if( (i == 2 )&&(j > 4) ){

                for(bi=i-2; bi<576; i++){
                    for(bj=j-5; bj<720; j++){
                            cout << "bi: " << bi << "   bj: " << bj << endl;
                            img.pixel[bi*img.width+bj] = image_buffer.pixel[bi*image_buffer.width+bj];
                    }
                }

            }   
        }
    }
}

要比较dir2中的文件,请使用以下命令。

git diff branch1:file1.c branch2:file1

您也可以比较不同文件夹中不同文件名的文件,即以下命令可以。

git diff branch1:../dir2/file2.c branch2:../dir2/file2.c

答案 1 :(得分:0)

git diff yourbranch1 yourbranch2 -- yourfile.txt

或使用meld或git diff工具。

答案 2 :(得分:0)

您不需要完整路径,但需要相对于相关树的路径。

来自git-diff文档:

 git diff [--options] <commit> <commit> [--] [<path>…​]

   This is to view the changes between two arbitrary <commit>.

使用:

git diff master access-ui My.Web/App/tenant/views/propertymanagement/index.less