简体   繁体   English

合并一个 git 分支,同时排除对某些目录的更改

[英]Merge a git branch, while excluding changes to some directory

I would like to merge changes from a branch B to my branch A, in such a way that the merge excludes any changes to a given directory.我想将分支 B 的更改合并到我的分支 A,这样合并会排除对给定目录的任何更改。 The problem here is that I have some commits which span changes over multiple directories, one of which needs to be excluded.这里的问题是我有一些跨越多个目录的提交,其中一个需要被排除。

Is something like that possible, for example, with history rewriting?类似的事情是否可能,例如,历史重写?

To clarify, my directory structure is:为了澄清,我的目录结构是:

root/x
root/y
root/z

some of the commits affect all three directories.一些提交影响所有三个目录。 Now, I would like to merge in such a way that I have changes in the history to both y and z , but not to x .现在,我想以这样一种方式合并,即我在历史中对yz都有更改,但对x没有更改。

You can merge the other branch without committing it, then resetting the state of the directory:您可以合并另一个分支而不提交它,然后重置目录的 state:

git merge --no-commit <branch>
git reset root/x
git commit

better yet to split your commits as mentioned by @useless in his answer最好按照@useless 在他的回答中提到的那样拆分您的提交

If your changes are all still local, the easiest way is by splitting your commits into genuinely orthogonal changes you can merge independently.如果您的更改仍然是本地的,最简单的方法是将您的提交拆分为真正正交的更改,您可以独立合并。


Dead link repair: try this link instead (or just see your local manpage for git rebase ), and search down for Splitting Commits .死链接修复:尝试使用此链接(或仅查看git rebase的本地联机帮助页),然后向下搜索Splitting Commits

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM