In a repository, there’s a dev branch and a main branch. There’s been a few commits in the dev branch and I want to take a specific commit to the main branch. I’m using Azure DevOps/GitHub Desktop and everything I’ve tried, it appears to take all the commits and not just the specific commit. I can’t push directly to main; I need to use a pull request. How can I merge a single commit?
I’ve tried to cherry pick the commit from dev to a new branch and then create a pull request from the new branch to main but that appears to pick all commits from the dev branch.
3
I need to use a pull request. How can I merge a single commit?
Based on your requirement, you can try the following steps to do the cherry pick in Azure DevOps:
Step1: Create a new branch based on main.
Step2: Navigate to Repos -> Commits -> Select the target One commit. Then you can use the Cherry Pick option to create a new branch based on the new branch in Step1.
For example:
Then you can select the branch.
Step3: It will automatically create a Pull Request and contain only one commit.
For example: From cherry pick branch to main branch
What exactly have you tried? I’d suggest using the shell for this:
# go to target branch
git checkout main
# find the hash of the commit to cherry-pick
git log dev
# the out put should be the history of commits with hashes <1> / <2> / <3> ...
git cherry-pick <2> # pick commit with hash <2> for example
4
git checkout main
git cherry-pick <commit-hash>
If any conflict resolve them:
git add .
git cherry-pick --continue
merge a single commit:
git rebase -i HEAD~(number of commit that you want to merge)
it apear a GNU nano : change pick to s or squash
I run :
git rebase -i HEAD~2
pick d6fa7b5 nth employee salary
pick fde8554 1st employee
.....
change pick to s:
pick d6fa7b5 nth employee salary
s fde8554 1st employee
press : Ctrl+X then Ctrl + Y,Enter,Ctrl+y
then all commit become a single commit.
Note : Sometime there are a validation to direct commit or cherry pic in main branch. After pull request it merged to main branch. please check this.