Cherry-picking a Commit from Feature Branch into Master
The Nautilus application development team needed to merge a specific commit from the feature branch into the master branch of the /opt/news.git repository. The required commit had the message “Update info.txt”. The task was to cherry-pick this commit into master and push the changes to the remote repository.
Steps Performed
1. Navigate to the repository
cd /usr/src/kodekloudrepos/news
2. Identify the required commit
Listed commit history in the feature branch to find the hash of the commit with the message Update info.txt:
git log --oneline feature
Example output:
a1b2c3d Update info.txt
f6e7g8h work in progress changes
1234abc initial commit
The commit hash for Update info.txt was noted as a1b2c3d.
3. Switch to the master branch
git checkout master
4. Cherry-pick the commit
Applied the specific commit from the feature branch to master:
git cherry-pick a1b2c3d
This brought only the Update info.txt commit into the master branch without merging all feature branch changes.
5. Push changes to remote
git push origin master
Outcome
- The commit Update info.txt from
featurewas successfully merged intomaster. - The repository history remains clean, as only the required commit was cherry-picked.
- Changes were pushed to the remote, ensuring the team can now access the updated
masterbranch.
Top comments (0)