Table of contents
Git Stash:
The git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy. For example: $ git status On branch main Changes to be committed: new file: style.
Cherry-pick:
git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes.
Resolving Conflicts:
Git can handle most merges on its own with automatic merging features. A conflict arises when two separate branches have made edits to the same line in a file, or when a file has been deleted in one branch but edited in the other. Conflicts will most likely happen when working in a team environment.
Task-01
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-02
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.\
- on Day 10 and reverted to this commit:
After bug fixing, this is the new feature with minor alteration.
- Commit the changes with the message "Added feature2.1 in development branch":
git branch development
git branch
git add version01.txt
git commit -m "Added feature2.1 in development branch"
Line2>> After bug fixing, this is the new feature with minor alteration”
Commit this with message “ Added feature2.1 in development branch”
- Add the following line after the previous change:
This is the advancement of the previous feature.
- Commit the changes with the message "Added feature2.2 in development branch":
git add version01.txt
git commit -m "Added feature2.2 in development branch"
- Add the following line after the previous change:
Feature 2 is completed and ready for release.
- Commit the changes with the message "Feature2 completed":
git add version01.txt
git commit -m "Feature2 completed"
- Switch to the production branch:
git checkout production
All these commits messages should be reflected in Production branch too which will come out from Master branch
git rebase development
- Push the changes to the remote repository:
git push origin production
Task-03
In Production branch Cherry pick Commit “Added feature2.2 in development branch” and added 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
- First, make sure you are on the Production branch:
git checkout production
- Cherry-pick the commit using its SHA hash:
git cherry-pick <commit-SHA>
Replace
<commit-SHA>
with the actual SHA hash of the "Added feature2.2 in development branch" commit.- Once the cherry-pick is complete, open the file where you want to add the new lines and edit it:
nano <file-name>
- Go to the line after Line3 and add the following text:
This is the advancement of previous feature
- Go to the next line and add the following text:
Added few more changes to make it more optimized
Save and exit the file.
Finally, commit the changes:
git add <file-name>
git commit -m "Added advancement and optimization to feature 2.2"