Deep Dive Into Git And GitHub II

Deep Dive Into Git And GitHub II

·

3 min read

🔸Git Stash: Saving Work in Progress🤔

  • Consider that you are creating a painting or a story. Midway through, someone asks for your assistance with something else. You must complete your work if you don't want to lose your progress. Git stash functions as a kind of enchanted bookmark that saves your work momentarily so you can return to it later.

  • You must first create a new branch and make some changes to it before you can use Git stash. After that, you can save those changes using the git stash command. By doing this, the changes will be recorded in a new stash instead of remaining in your working directory. These adjustments can be made later. The list of stored changes is displayed by the git stash list command.

  • Additionally, you can delete a stash using git stash drop and all the stashes at once using git stash clear.

🔸Git Cherry-Pick: Choosing Specific Changes ❗

  • Using the Git cherry-pick command, you can pick out particular commits from one branch and apply them to another. When you want to selectively apply changes made in one branch to another, this can be helpful.

  • You must first create two new branches and commit some changes to them before you can use git cherry-pick. The specific commits from one branch are then chosen and applied to the other branch using the git cherry-pick command with the specified commit_hash.

🔸Resolving Conflicts:

  • When merging or rebasing branches that have diverged, conflicts can arise, and you must manually resolve the conflicts before git can continue with the merge/rebase. The git status command displays the files that have conflicts, the git diff command compares the versions that are at odds, and the git add command is used to add the files that have been resolved.

🔸Understanding through Hand-On :

  • Task 1:

  • To create a new branch we use "git checkout -b branch name" and make changes by creating and modifying files.

  • Create another branch , make changes ad commit them and bring the changes back from stash using git stash pop and apply them on top of new commits

  • Task 2:

  • Now , change the branch to dev to make the commits as given in the task

  • Check the commits made using "git log"

  • All these commits messages should be reflected in the Production branch too which will come out from the Master branch (Hint: try rebase)

  • Task 3:

  • Change your branch to the production branch (if you are not in production),pick commit using git cherry-pick <commit-hash> of the commit you want to pick, and then add the lines as given in the task.

  • Resolving the error :

  • Commit - Optimized Feature

I hope now you know about git stash , how to use it , git cherry-pick

Stay tuned for more updates

Happy Learning :D