Table of contents
Git Stash:
Git stash is a Git command that allows you to temporarily save changes that are not yet ready to be committed. This is useful when you need to switch to a different branch or work on a different task, but don't want to commit incomplete changes to the current branch.
When you run git stash
, Git takes all the changes that you have made to tracked files and saves them in a "stash" - a stack of temporary commits. The changes are removed from your working directory, leaving you with a clean slate to work on.
Cherry-pick:
git cherry-pick
is a Git command that allows you to apply a specific commit or a range of commits from one branch to another. It is useful when you want to selectively apply changes from one branch to another, without having to merge the entire branch.
To use git cherry-pick
, you first need to identify the commit or commits that you want to apply. You can do this by looking at the commit history of the source branch and identifying the commit hashes of the desired changes.
Once you have identified the commit or commits, you can switch to the target branch and run the git cherry-pick
command followed by the commit hash(es). Git will then apply the changes from the specified commit(s) to the current branch.
If there are any conflicts between the changes being cherry-picked and the current state of the target branch, Git will prompt you to resolve the conflicts manually.
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.
Now See all commit:
Here, You can see new commits at the top after a stash
Task-02
- In version01.txt of development, the branch adds the 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”
Line3>> This is the advancement of previous feature
Commit this with message “ Added feature2.2 in development branch”
Line4>> Feature 2 is completed and ready for release
Commit this with message “ Feature2 completed”
All these commits messages should be reflected in Production branch too which will come out from Master branch (Hint: try rebase).
Make sure you are on the development
branch:
Open the version01.txt
file in a text editor:
Add the following lines after "This is the bug fix in the development branch":
Commit the changes with the message "Added feature2.1 in development branch":
Add the changes to the staging area:
Commit the changes with the message "Feature2 completed":
Switch to the master
branch:
Use git rebase
to apply the commits made on the development
branch onto the master
branch:
Push the changes to the remote repository:
Note: here I have taken master as a Production branch
Task-03
In the Production branch Cherry pick Commit “Added feature2.2 in development branch” and added the below lines in it:
The line to be added after Line3>> This is the advancement of the previous feature
Line 4>>Added a few more changes to make it more optimized.
Commit: Optimized the feature
Make sure you are on the production
branch:
Cherry-pick the commit from the development
branch:
git cherry-pick <commit hash of development branch>
Edit the file, add it and commit.
git add <file name>
git commit -m "optimized the feature"
Push the changes to the production
branch:
git push origin production
\==========================THANKYOU=========================