Cherry-Picking a Specific Commit
Cherry-picking allows you to select a single commit from one branch (or repository) and apply it to your branch.
1. Add the remote repository
Add the remote repository from which you want to cherry-pick the commit.
Example
git remote add <remote-name> https://github.com/username/repo.git
- Replace
remote-namewith the branch name. - Replace
username/repowith the username and repository you want to pull from.
2. Fetch the latest changes from the remote
Example
git fetch <remote-name>
3. Find the commit hash
You need to know the commit hash you want to cherry-pick. You can find the hash in the other repository's commit history.
4. Cherry-pick the commit
Example
git cherry-pick <commit-hash>
5. Resolve conflicts
If there are any merge conflicts, Git will prompt you to resolve them.
6. Push the changes
After cherry-picking the commit and resolving conflicts, push the changes to your repository.
Example
git push origin <branch-name>
- Replace
branch-namewith your actual branch name (e.g.,master).