Nikola Knezevic
Nikola Knezevic

Reputation: 799

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.

Upvotes: 6

Views: 5528

Answers (2)

Useless
Useless

Reputation: 67772

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.

Upvotes: 3

knittl
knittl

Reputation: 265547

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

Upvotes: 8

Related Questions