【问题标题】:Git - how do i get which file or code is not exist ONLY IN 1 BRANCH while comparing 2 branch in git?Git - 在比较 git 中的 2 个分支时,如何获取仅在 1 个分支中不存在的文件或代码?
【发布时间】:2021-02-10 03:10:13
【问题描述】:

我想比较两个分支(masterlive),具体结果如下

当前问题

假设我在master 中有 2 个file

  • foo.js:

    foo.js内的值:

    console.log('inital foo')

  • bar.js:

    bar.js内的值:

    console.log('bar')
    

live 分支我有两个文件:

  • bar.js

    bar.js内的值:

    //another code that should
    //exist only in live branch
    ...
    console.log('bar')
    
  • Constants.js

    Constants.js 内的值:

    BaseURL = 'http://'
    Version = '1.0.1'
    

现在我想比较master中是否有一些文件/代码不存在live分支中

当前结果

git diff live master --name-only 输出结果:

foo.js
bar.js
Constant.js

预期结果

只需检查master 分支中不存在的任何更改/新文件live 分支

任何应该输出结果的命令:

foo.js

原因

live 中的bar.js 有另一个只应该存在于live 中的代码,并且由于masterliveconsole.log('bar'),因此不应显示结果

Constant.js 不应显示为结果,因为它在 live

有没有办法实现它?

【问题讨论】:

    标签: git git-diff


    【解决方案1】:

    我想你正在寻找这个命令:

    git diff live...master --name-only
    

    它的作用是比较 master 分支自 live 分支从它启动时发生的更改。你可以在the docs找到它。

    【讨论】:

    • 我认为git diff live...master --name-only 解决了Constants.js 不显示在live 中,但是bar.js 怎么样?无论如何+1 :)
    • @flix bar.js 何时添加到每个分支?
    • 当从master 拉到live 或手动创建时,这是我的情况的一个条件,有时我需要从master 拉它(因为代码)或只是手动更改(例如仅更改版本号,所以我没有从“master”中提取,而是从live 分支手动键入以匹配master 版本号)
    猜你喜欢
    • 2021-03-13
    • 2020-01-01
    • 2011-03-25
    • 2022-11-11
    • 1970-01-01
    • 2018-03-17
    • 2020-02-20
    • 1970-01-01
    • 2019-11-21
    相关资源
    最近更新 更多