Git Stash:
git stash
is a command that allows you to temporarily save changes that you don't want to commit immediately. It's particularly useful when you're in the middle of working on something, and you need to switch to another branch.
Cherry-pick:
git cherry-pick <commit id>
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.
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 conflictsgit diff
command shows the difference between the conflicting versionsgit add
command is used to add the resolved files.
Task 1: Create a new branch and make some changes to it
To create a new branch and switch to the new branch
sudo git branch Dev
sudo git checkout Dev
Task 2: Use git stash to save the changes without committing them
sudo git stash
Task 3: Switch to a different branch, make some changes and commit them
sudo git branch main
sudo git checkout main
Task 4: Use git stash pop to bring the changes back and apply them on top of the new commits
sudo git stash pop
cat file.txt
By executing the above command, our changes back from stash
Then Add and commit the file
sudo git add file.txt
sudo git commit -m "main branch commit"
Task 5: In version01.txt of development branch add below lines after “This is the bug fix in development branch” that you added in Day10 and reverted to this commit.
Line2 --> After bug fixing, this is the new feature with minor alteration
Commit this with message "Added feature2.1 in development branch"
vi Version01.txt
Add the content in Version01.txt
After bug fixing, this is the new feature with minor alteration
Add & commit the changes
sudo git add Version01.txt
sudo git commit -m "Added feature2.1 in development branch"
Line3 --> This is the advancement of previous feature
Commit this with message “ Added feature2.2 in development branch”
vi Version01.txt
Add the content
This is the advancement of the previous feature
Add & commit changes
sudo git add Version01.txt
sudo git commit -m "Added feature2.2 in development branch"
Line 4 --> Feature 2 is completed and ready for release
Commit this with the message “ Feature2 completed”
vi Version01.txt
Add the content
Feature 2 is completed and ready for release
Add & Commit the changes
sudo git add Version01.txt
sudo git commit -m "Feature2 completed"
Task 6: All these commits messages should be reflected in Production branch too which will come out from Master branch
Now all commits should reflect in production branch
Switch to Production branch
sudo git checkout Production
sudo git rebase Develop
Kindly refer the screenshot for reference
Task 7: In Production branch Cherry pick Commit “Added feature2.2 in development branch”
- To cherry-pick from in production branch, first do
sudo git log
- copy HashID which you want to cherry-pick
sudo git cherry-pick <hashID>
add below lines in it:
Line to be added after Line3 --> This is the advancement of previous feature
Line4 -->Added few more changes to make it more optimized.
Commit: Optimized the feature
vi Version01.txt
Add the below lines
Added few more changes to make it more optimized.
Add & Commit file
sudo git add Version01.txt sudo git commit -m "Optimized the feature"
Happy Learning!!
Thanks For Reading :)