Michele Volpato

Michele Volpato

Copy a single commit to another branch using cherry-pick

Tips

Today I was working on a new feature. I created a new branch feature/add-gallery-button.

While a was working on it, I noticed some code that, if improved, would have made the development process much easier. So I improved it.

Once I was done, I committed the code and pushed to the remote. I started a merge request and assigned it to another developer.

Then, after a celebration coffee, I started working on yet another new feature, feature/update-log-component, and I wanted to use the code improvements from feature/add-gallery-button.

Instead of copying the code manually, thus creating two commits in the repository history with the same change, it would have been nice to bring the commit from feature/add-gallery-button to feature/update-log-component.

This is possible with git cherry-pick.

You only need the SHA of the commit you want to copy, let’s say 4350a96303c474812523c1214f50ffda1f2e437a.

Be sure to checkout the branch you are working on now.

git checkout feature/update-log-component
git cherry-pick 4350a96303c474812523c1214f50ffda1f2e437a

en voilà, the improved code is also on my current branch.

Get a weekly email about Flutter

Subscribe to get a weekly curated list of articles and videos about Flutter and Dart.

    We respect your privacy. Unsubscribe at any time.

    Leave a comment