Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge a git branch, while excluding changes to some directory

Tags:

git

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.

like image 477
Nikola Knezevic Avatar asked Aug 10 '11 16:08

Nikola Knezevic


1 Answers

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

like image 135
knittl Avatar answered Nov 15 '22 01:11

knittl