Git Stash
In git stash command is used to temporarily save changes that you've made to your working directory but are not ready to commit.
This can be useful when you need to switch to a different branch, pull changes from a remote repository, or perform other operations that might interfere with your current changes.
Stashing allows you to store your changes in a safe place, revert your working directory to a clean state, and later reapply those changes.
- Stash changes:
- git stash save "Your stash message"
Do other tasks (switch branches)
Retrieve stashed changes:
- git stash apply
- Optionally, remove the stash:
- git stash drop
This allows you to switch between tasks without committing incomplete changes.
Cherry-pick
In Git, 'cherry-pick' is a command used to apply a specific commit from one branch to another.
It allows you to pick and choose individual commits and apply them to another branch, providing a way to selectively transfer changes between branches.
Let's say you have a branch called 'manasa-branch' with a commit you want to apply to your 'main' branch.
Identify the commit you want to cherry-pick use the below command :
- git log
Switch to the branch where you want to apply the commit:
- git checkout main
Cherry-pick the commit:
- git cherry-pick <commit-hash>
Resolve any conflicts: If there are conflicts during the cherry-pick process, you need to resolve them manually. Git will mark the conflicted files, and you can use
git status
to see which files need attention.Complete the cherry-pick:
After resolving conflicts, add the changes and complete the cherry-pick.
git add .
git cherry-pick --continue
you can abort the cherry-pick if needed:
- git cherry-pick --abort
THANK YOU FOR READING!