You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Git基于./repo与./new的差异创建本地test分支?

Solution: Create test Branch with ./repo vs ./new Differences

Here's the most concise, step-by-step approach using Git and diff:

  1. Initialize the test branch from master
    First, navigate into your local repo and create the new branch in one command:

    cd ./repo && git checkout -b test master
    

    This switches you to the test branch, which starts as an exact copy of master.

  2. Apply the directory differences
    From inside the repo folder, generate a unified diff between the current repo and the ../new directory, then apply those changes directly to the test branch:

    diff -ru --exclude='.git' . ../new | git apply
    
    • -r: Recursively compare subdirectories
    • -u: Output in unified format (compatible with git apply)
    • --exclude='.git': Skip the repo's Git metadata folder (since ./new doesn't have it)
  3. Commit the changes
    Stage all modified/added files and commit them to the test branch:

    git add . && git commit -m "Integrate changes from ./new directory"
    

Quick Notes:

  • If you prefer not to pipe directly, you can generate a patch file first (diff -ru --exclude='.git' repo new > repo-new.patch), then run git apply ../repo-new.patch from inside the repo.
  • This approach handles all text files and unversioned subdirectories from ./new, adding new files and updating existing ones to match ./new.

内容的提问来源于stack exchange,提问作者Martin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:37:58