Table of contents
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 Git stash, 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. 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 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. git status command shows the files that have conflicts, git diff command shows the difference between the conflicting versions and git add command is used to add the resolved files.
Task-01
- Create a new branch and make some changes to it already created a new branch called
feature_branch
lets enter in to it and make some changes
Bash
git checkout feature_branch
Bash
echo "jus now we have enter into Day-11 task" >> demo.txt
Bash
git add demo.txt
- Use git stash to save the changes without committing them:
Bash
git stash
- Switch to a different branch, make some changes, and commit them:
Bash
git checkout -b new_branch
Bash
echo "this is new file" > new_demo.txt
Bash
cat new_demo.txt
Bash
git add new_demo.txt
Bash
git commit -m "added new demo file"
- Use git stash pop to bring the changes back and apply them on top of the new commits:
Bash
git stash pop
Bash
git commit -m "added demo.txt file from the feature_branch"
Task-02
Inversion01.txt
of the development branch, add the specified lines after the existing content:
- Now , change the branch to dev to make the commits as given in the task
Bash
git checkout dev
Bash
echo "After bug fixing, this is the new feature with minor alteration" >> version01.txt
Bash
git add version01.txt
Bash
git commit -m "Added feature2.1 in development branch"
Bash
echo "This is the advancement of the previous feature" >> version01.txt
Bash
git add version01.txt
Bash
git commit -m "Added feature2.2 in development branch"
Bash
echo "Feature 2 is completed and ready for release" >> version01.txt
Bash
git add version01.txt
Bash
git log --oneline
- Reflect these commit messages in the Production branch using rebase:
Bash
git checkout -b production
Bash
git rebase dev && git log --oneline
Task-03
- Cherry pick the commit "Added feature2.2 in development branch" into the Production branch:
Bash
git cherry-pick <commit_hash_of_feature2.2>
- Resolving the error by add the specified lines after "This is the advancement of the previous feature"
Bash
echo "Added few more changes to make it more optimized." >> version01.txt
Bash
git add version01.txt
Bash
git commit -m "Optimized the feature"
Bash
cat version01.txt
Happy Learning
Thanks For Reading! :)
-SriParthu๐