是否可以将本地Git分支中子目录的更改合并到远程Git分支,或者是“全部或全部不合并”?
例如,我有:
branch-a
- content-1
- dir-1
- content-2和
branch-b
- content-1
- dir-1
- `content-2我只想将branch-a dir-1的内容与branch-b dir-1的内容合并。
发布于 2014-09-09 23:57:47
对于我的例子,假设你有一个分支'source‘和一个分支'destination’,这两个分支都反映了它们自身的上游版本(或者不是,如果只是本地的话),并被拉到最新的代码。假设我想要存储库中名为newFeature的子目录,它只存在于“源”分支中。
git checkout destination
git checkout source newFeature/
git commit -am "Merged the new feature from source to destination branch."
git pull --rebase
git push它比我见过的任何其他东西都要简单得多,这对我来说是完美的,found here。
请注意,这不是“真正的合并”,因此在目标分支中不会有关于newFeature的提交信息,只有对该子目录中文件的修改。但是,由于您可能会在稍后合并整个分支,或者将其丢弃,所以这可能不是问题。
发布于 2020-03-20 20:32:01
假设操作员有两个分支,但是只想将-1\f25-1\f6分支-1\f25 a-1\f6中的-1\f25-1\f6合并到-1\f25-1\f6分支-b-1\f25-1\f6中
# Make sure you are in the branch with the changes you want
git checkout branch-a
# Split the desired folder into its own temporary branch
# This replays all commits, so it could take a while
git subtree split -P dir-1 -b temp-branch
# Enter the branch where you want to merge the desired changes into
git checkout branch-b
# Merge the changes from the temporary branch
git subtree merge -P dir-1 temp-branch
# Handle any conflicts
git mergetool
# Commit
git commit -am "Merged dir-1 changes from branch-a"
# Delete temp-branch
git branch -d temp-branch发布于 2012-09-18 17:07:46
这是我从Eclipse的一个forum thread那里得到的,它就像一个护身符:
git checkout source-branch
git checkout target-branch <directories-or-files-you-do-**NOT**-want>
git commit
git checkout target-branch
git merge source-branchhttps://stackoverflow.com/questions/1214906
复制相似问题