Git Stash:
Git stash is a Git command used to temporarily store changes that are not ready to be committed. It's useful for switching tasks or branches without committing incomplete work, maintaining a clean workspace, collaborating efficiently, and aiding conflict resolution during merges or rebases. Essentially, it helps manage changes flexibly and organize workflow effectively.
git stash list command shows the list of stashed change.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 used to apply specific commits from one branch to another. It allows developers to pick individual commits and apply them onto another branch, independent of the commit history.
Why we use it:
Isolated Changes: Cherry-pick is helpful when you want to selectively apply changes from one branch to another without merging entire branches, keeping changes isolated.
Fixing Issues: It's useful for applying bug fixes or specific changes from one branch to another, such as applying a hotfix from a release branch to a development branch.
Maintaining Clean History: Cherry-pick enables developers to maintain a clean commit history by selecting only relevant commits to apply to a branch.
How to use it:
git cherry-pick <commit-hash>
Replace
<commit-hash>
with the hash of the commit you want to cherry-pick.Example: Suppose you have two branches,
feature
andmaster
, and you want to apply a commit fromfeature
tomaster
:Checkout the
master
branch:git checkout master
Cherry-pick the desired commit from
feature
:git cherry-pick <commit-hash>
This will apply the changes introduced by the specified commit from the
feature
branch onto themaster
branch.By cherry-picking specific commits, developers can manage changes more granularly, applying only the necessary modifications to relevant branches.
Resolving Conflicts:
Resolving conflicts in Git occurs when there are conflicting changes between different branches or commits. It happens when Git cannot automatically merge changes due to conflicting edits made to the same part of a file.
We use it :
Integration of Changes: Conflicts need to be resolved to integrate changes from different branches or contributors into a single codebase.
Maintaining Code Quality: Resolving conflicts ensures that the final codebase is consistent and functions properly without unintended behavior resulting from conflicting changes.
Collaboration: It enables collaboration among team members by facilitating the merging of changes made by multiple developers working on the same project.
How to use it:
Identify Conflicts: Git marks conflicted files in your working directory. These files will contain conflict markers indicating conflicting changes.
Open Conflicted Files: Open the conflicted files in your text editor. Inside the files, you'll see the conflicting changes surrounded by conflict markers (
<<<<<<<
,=======
,>>>>>>>
).Resolve Conflicts: Edit the conflicted files manually to resolve the conflicts. Remove the conflict markers and choose which changes to keep or combine.
Add Changes: After resolving conflicts, stage the modified files using
git add
.Commit Changes: Once all conflicts are resolved, commit the changes using
git commit
.
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.
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).
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.
Commit: Optimized the feature