如何用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:
Initialize the
testbranch frommaster
First, navigate into your local repo and create the new branch in one command:cd ./repo && git checkout -b test masterThis switches you to the
testbranch, which starts as an exact copy ofmaster.Apply the directory differences
From inside the repo folder, generate a unified diff between the current repo and the../newdirectory, then apply those changes directly to thetestbranch:diff -ru --exclude='.git' . ../new | git apply-r: Recursively compare subdirectories-u: Output in unified format (compatible withgit apply)--exclude='.git': Skip the repo's Git metadata folder (since./newdoesn't have it)
Commit the changes
Stage all modified/added files and commit them to thetestbranch: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 rungit apply ../repo-new.patchfrom 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
相关产品推荐
相关产品推荐

