DevOps(Day-12) - git & gitstach


Suppose you are implementing a new feature for your product. Your code is in progress and suddenly a customer escalation comes. Because of this, you have to keep aside your new feature work for a few hours. You cannot commit your partial code and also cannot throw away your changes. So you need some temporary space, where you can store your partial changes and later on commit it.

In Git, the stash operation takes your modified tracked files, stages changes, and saves them on a stack of unfinished changes that you can reapply at any time.

Commands:-

  1. To use Git stash, you first create a new branch and make some changes to it. Then you can use the command "git stash" to save those changes. This will remove the changes from your working directory and record them in a new stash. You can apply these changes later. git stash list command shows the list of stashed changes.

  2. You can use "git stash pop" to retrieve the file in another branch after committing the priority file to a required branch.

  3. You can also use "git stash drop" to delete a stash and "git stash clear" to delete all the stashes.

Suppose you are working with a team of developers on a medium to large-sized project. Some changes were proposed by another team member and you want to apply some of them to your main project, but not all. Managing the changes between several Git branches can become a complex task, and you don't want to merge a whole branch into another branch. You only need to pick one or two specific commits. To pick some changes to your main project branch from other branches is called cherry-picking.

To use git cherry-pick, you first create two new branches and make some commits to them. Then you use the "git cherry-pick <commit_hash>" command to select the specific commits from one branch and apply them to the other.

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 conflicts.

git diff command shows the difference between the conflicting versions.

git add command is used to add the resolved files.

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 Dev branch Cherry pick Commit “Added feature2.2 in production 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

Thank you very much for reading my article.

Have a nice day.

Comments

Popular posts from this blog

DevOps(Day-97): Meta-Arguments in Terraform

DevOps(Day-95): Auto Scaling with Terraform

DevOps (Day-1) Introduction