0
0
Gitdevops~30 mins

Cherry-picking multiple commits in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Cherry-picking multiple commits
📖 Scenario: You are working on a project with multiple branches. You want to bring specific changes from one branch into another without merging the entire branch. This is useful when you only need some fixes or features from a different branch.
🎯 Goal: Learn how to cherry-pick multiple commits from one branch to another using Git commands.
📋 What You'll Learn
Create a new branch called feature from main
Make three commits on the feature branch with exact commit messages
Switch back to main branch
Cherry-pick two specific commits from feature branch onto main
Display the commit log on main to verify cherry-pick
💡 Why This Matters
🌍 Real World
Cherry-picking is used when you want to apply specific changes from one branch to another without merging all changes. For example, applying a bug fix from a development branch to the main branch quickly.
💼 Career
Understanding cherry-pick helps in managing code changes efficiently in team projects, especially when working with multiple branches and needing selective updates.
Progress0 / 4 steps
1
Create the feature branch and make commits
Create a new branch called feature from main. Then make three commits on feature branch with these exact commit messages in order: "Add login feature", "Fix login bug", and "Improve login UI".
Git
Need a hint?

Use git checkout -b feature main to create and switch to the feature branch. Use git commit --allow-empty -m "message" to create commits without changing files.

2
Switch back to main branch
Switch back to the main branch using the correct Git command.
Git
Need a hint?

Use git checkout main to switch back to the main branch.

3
Cherry-pick two commits from feature branch
Cherry-pick the commits with messages "Add login feature" and "Improve login UI" from the feature branch onto the main branch. Use the commit hashes to cherry-pick these commits.
Git
Need a hint?

Use git log feature --grep="commit message" --format=%H -n 1 to get the commit hash. Then use git cherry-pick <hash> to apply the commit.

4
Verify the cherry-picked commits
Run the command to show the commit log on the main branch and verify that the commits with messages "Add login feature" and "Improve login UI" are present.
Git
Need a hint?

Use git log --oneline to see the short commit messages on the current branch.