When merging a branch A with another branch B, how to exclude some commits from B to merge?
For example, B has 100 commits, how can I merge the specific 98 commit and exclude the 2?
When merging a branch A with another branch B, how to exclude some commits from B to merge?
For example, B has 100 commits, how can I merge the specific 98 commit and exclude the 2?
So for example if you're on branchB and you git add .
and git commit
you could git reset <file name>
for the ones you want to exclude then when you merge branchB into branchA it will only include the 98 that are committed.
git cherry-pickThat might be the command you want. It ables you to select the commits you want.
https://git-scm.com/docs/git-cherry-pick
git cherry-pick [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] [-S[]] … git cherry-pick --continue git cherry-pick --quit git cherry-pick --abort
Given one or more existing commits, apply the change each one introduces, recording a new commit for each. This requires your working tree to be clean (no modifications from the HEAD commit).
After the merge you could rebase interactively and exclude the unwanted commits:
git rebase -i HEAD~100
You may want to create an intermediate branch from the source do rebase -i and then merge that into your target branch.
Something like the following.
git checkout source
git checkout -b middle
git rebase -i HEAD~100 or commit-ish
git checkout target
git merge middle
If the changes are sequential/consecutive from the latest commit back then its easy.
First you would switch to the branch you merging into, lets call this branch 'des' and the branch with the changes 'src'.
git checkout dsc
Then, merge the src branch into des with the --no-commit option, this will merge the changes but will not create a commit.:
git merge --no-commit src
Then, use git log command (or your git gui/tools) to find the hash of the commit you want to exclude from. Finally Reset the dst branch to the commit before the unwanted commit using the git reset command:
git reset --hard a123456^
Now commit with a message:
git commit -m "Merge src into dsc (excluding unwanted commit)"