git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
Cink
V2EX  ›  git

如何获取 git merge 合并的两个分支的公共代码变更集

  •  1
     
  •   Cink · Mar 21, 2020 · 2807 views
    This topic created in 2276 days ago, the information mentioned may be changed or developed.

    小菜鸡一枚 求教一个 git 问题

    我用 git merge 合并了两个开发分支,然后获取 LOG 日志文件,通过 sed 处理得到的 merge 的代码变更集清单,此清单中既包括两个分支共同修改过的代码文件,也包括只有被合并分支改过的代码文件,现在我想只获取到公共部分的代码变更集,即在两个分支上都被修改过的文件(无论 git merge 操作是否产生冲突),有什么手段可实现么。

    git checkout dev-A
    git checkout dev-B
    git merge dev-A &> LOG
    

    示意图如下。 mmexport1584723577937.jpg 在 stackoverflow 上也提了个问题。 https://stackoverflow.com/questions/60778476/how-can-i-get-the-program-name-list-of-codes-which-changed-both-in-two-branches

    Supplement 1  ·  Mar 21, 2020

    这个是我 LOG 日志的内容,我会用 sed 来处理

    LOG :

    twd-place:
    Updating c6157fg..8eceqaa
    Fast-forward
    pom.xml | 223 +++++++++++----------
    .../auto/srf/place/PlaceAutoServiceImpl.java | 26 ++-
    .../auto/srf/place/srf_auto_place.xml | 23 ++-
    
    twd-head:
    Updating 082a5cd..cr2dedc
    Fast-forward
    pom.xml | 26 +-
    .../gather/Gather.java | 44 ++-
    
    Auto-merging src/main/scripts/TWD.properties
    CONFLICT (content): Merge conflict in src/main/scripts/TWD.properties
    Auto-merging src/main/resources/com/twd/head/config/discovery.xml
    CONFLICT (content): Merge conflict in src/main/resources/com/twd/head/config/discovery.xml
    

    处理完以后会是这样的内容,就是我需要的程序变更清单了。

    LOG :

    twd-place:
    pom.xml
    .../auto/srf/place/PlaceAutoServiceImpl.java
    .../auto/srf/place/srf_auto_place.xml
    
    twd-head:
    pom.xml
    .../gather/Gather.java
    src/main/scripts/TWD.properties
    src/main/resources/com/twd/head/config/discovery.xml
    

    比如.../auto/srf/place/PlaceAutoServiceImpl.java 这个文件是只在 dev-A 分支上做了修改,dev-B 分支上没有修改,我就需要在清单里把它删除,只留下两个分支上都修改过的程序文件名称。

    4 replies    2020-03-23 08:50:16 +08:00
    momocraft
        1
    momocraft  
       Mar 21, 2020
    **获取文件** 是什么意思 文件名?

    grep -f <(git diff --name-only BASE dev-A) <(git diff --name-only BASE dev-B)

    这样可吗?
    Cink
        2
    Cink  
    OP
       Mar 21, 2020 via Android
    这个是我 LOG 日志的内容,我会用 sed 来处理
    ---
    `LOG` :
    ```
    twd-place:
    Updating c6157fg..8eceqaa
    Fast-forward
    pom.xml | 223 +++++++++++----------
    .../auto/srf/place/PlaceAutoServiceImpl.java | 26 ++-
    .../auto/srf/place/srf_auto_place.xml | 23 ++-

    twd-head:
    Updating 082a5cd..cr2dedc
    Fast-forward
    pom.xml | 26 +-
    .../gather/Gather.java | 44 ++-

    Auto-merging src/main/scripts/TWD.properties
    CONFLICT (content): Merge conflict in src/main/scripts/TWD.properties
    Auto-merging src/main/resources/com/twd/head/config/discovery.xml
    CONFLICT (content): Merge conflict in src/main/resources/com/twd/head/config/discovery.xml
    ```
    ---
    处理完以后会是这样的内容,就是我需要的程序变更清单了。
    ---
    `LOG` :
    ```
    twd-place:
    pom.xml
    .../auto/srf/place/PlaceAutoServiceImpl.java
    .../auto/srf/place/srf_auto_place.xml

    twd-head:
    pom.xml
    .../gather/Gather.java
    src/main/scripts/TWD.properties
    src/main/resources/com/twd/head/config/discovery.xml
    ```
    ---
    比如.../auto/srf/place/PlaceAutoServiceImpl.java 这个文件是只在 dev-A 分支上做了修改,dev-B 分支上没有修改,我就需要在清单里把它删除,只留下两个分支上都修改过的程序文件名称。
    Cink
        3
    Cink  
    OP
       Mar 21, 2020
    @momocraft 已更新问题描述
    Cink
        4
    Cink  
    OP
       Mar 23, 2020 via Android
    。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2826 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:29 · PVG 12:29 · LAX 21:29 · JFK 00:29
    ♥ Do have faith in what you're doing.