简体   繁体   中英

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. 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 .

You can merge the other branch without committing it, then resetting the state of the directory:

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

better yet to split your commits as mentioned by @useless in his answer

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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