Is it possible to exclude specific commits when doing a git merge?
Solution 1:
I've found a solution that works for me in the Pro Git book.
Let's say you want to exclude the file config.php
.
On branch A:
Create a file named
.gitattributes
in the same dir, with this line:config.php merge=ours
. This tells git what strategy to use when merging the file. In this case it always keep your version, ie. the version on the branch you are merging into.Add the
.gitattributes
file and commit
On branch B: repeat steps 1-2
Try merging now. Your file should be left untouched.
Solution 2:
Create a new branch, rebase the branch interactively and drop commits you don't want, and then merge that.
You can't take changes out of the middle of a branch without rehashing, but the right thing will happen when it sees the same changes in a later merge (e.g. from cherry-picking and what-not).