Git Stash
Git stash is a command that allows you to temporarily save changes you have made in your working directory, without committing them. This is useful when you need to switch to a different branch to work on something else, but you don't want to commit the changes you've made in your current branch yet.
To use the git stash command, you first create a new branch and make some changes to it. Then you can use the command Git stash to save those changes. This will remove the changes from your working directory and record them in a new stash. You can apply these changes later. The git stash list command shows the list of stashed changes.
You can also use Git stash drop to delete a stash and Git stash clear to delete all the stashes.
Cherry-pick
Git cherry-pick is a command that allows you to select specific commits from one branch and apply them to another. This can be useful when you want to selectively apply changes that were made in one branch to another.
To use Git cherry-pick, you first create two new branches and make some commits to them. Then you use Git cherry-pick <commit_hash> command to select the specific commits from one branch and apply them to the other.
Resolving Conflicts
Conflicts can occur when you merge or rebase branches that have diverged, and you need to manually resolve the conflicts before Git can proceed with the merge/rebase. The git status command shows the files that have conflicts, the Git diff command shows the difference between the conflicting versions and Git add command is used to add the resolved files.
Task 1: Using git stash
commands
Create a new branch and make some changes to it.
Use git stash to save the changes without committing them.
Switch to a different branch, make some changes and commit them.
Use git stash pop to bring the changes back and apply them on top of the new commits.
Task 2: Using git rebase branchname
command.
The git rebase
command is used in Git to move or combine a sequence of commits from one branch onto another branch. When you run git rebase branchname
, it means you want to rebase your current branch on top of the specified branchname
.
Here's the basic syntax of the git rebase
command:
git rebase <branchname>
Task 3: Using git cherry-pick commit_id
command
The git cherry-pick
command allows you to pick a specific commit from one branch and apply it to another branch. This is useful when you want to incorporate changes from a single commit, rather than merging or rebasing an entire branch. It essentially lets you choose individual commits to copy to a different branch.
The basic syntax of the git cherry-pick
command is as follows:
git cherry-pick <commit-hash>
It is a commit that creates a new commit on the current branch, and the commit message and content will remain the same as in the original commit. The new commit will have a different commit hash due to its different parent history. Cherry-picking should be used with caution, especially if the commit being picked has dependencies on other changes not present in the target branch.
Thanks for reading!
#devops#90DaysOfDevops#TrainWithShubham
Let's connect on Linkedin - linkedin.com/in/namya-khullar-7b5758200