git cherry-pick should be your answer here.
Apply the change introduced by an existing commit.
Do not forget to read bdonlan's answer about the consequence of cherry-picking in this post:
"Pull all commits from a branch, push specified commits to another", where:
A-----B------C
\
\
D
becomes:
A-----B------C
\
\
D-----C'
The problem with this commit is that git considers commits to include all history before them
Where C' has a different
SHA-1ID.
Likewise, cherry picking a commit from one branch to another basically involves generating a patch, then applying it, thus losing history that way as well.
Answer from VonC on Stack OverflowThis changing of commit IDs breaks git's merging functionality among other things (though if used sparingly there are heuristics that will paper over this).
More importantly though, it ignores functional dependencies - if C actually used a function defined in B, you'll never know.
git cherry-pick should be your answer here.
Apply the change introduced by an existing commit.
Do not forget to read bdonlan's answer about the consequence of cherry-picking in this post:
"Pull all commits from a branch, push specified commits to another", where:
A-----B------C
\
\
D
becomes:
A-----B------C
\
\
D-----C'
The problem with this commit is that git considers commits to include all history before them
Where C' has a different
SHA-1ID.
Likewise, cherry picking a commit from one branch to another basically involves generating a patch, then applying it, thus losing history that way as well.
This changing of commit IDs breaks git's merging functionality among other things (though if used sparingly there are heuristics that will paper over this).
More importantly though, it ignores functional dependencies - if C actually used a function defined in B, you'll never know.
You can use git cherry-pick to apply a single commit by itself to your current branch.
Example: git cherry-pick d42c389f
Merge but exclude certain commits
How can we merge only specific files from one branch into another in Azure DevOps, even if those files are part of the same commit or spread across multiple commits?.
How to merge branches to a specific commit
Remove all changes merged from a specific branch
I have a branch test1 from which I created a new branch test2. It looks like below.
test1 => X => Y => other commits => test2 where X and Y are two commits.
Now, I want to merge all changes in test2 branch back to test1 branch, except for the changes associated with the two commits X and Y. It's also worth mentioning that the changes in commits X and Y are in files that are not touched by the other commits.
How do I do this? (Also, I don't want such merge to automatically commit.)
I have two branches, main and develop. Lets say that this is my current commit history:
A - B - C - D (main) (tag 1.0.0) - E - F - G (tag 1.0.1) - H (develop)
I want to bring main to G (tag 1.0.1) so that it is one commit behind develop. Note that, I want all commits between main and G to also be included. Would I use cherry-pick or is there a better way?