DevOps Classroom Series – 24/Nov/2021

Git branches contd…

  • The current DAG for REL_1.0 and REL_1.1 Preview

  • Now lets make a commit in REL_1.0 Preview

  • The changes which we have done in this commit (c070965) in REL_1.0 branch are also required on REL_1.1 branch

  • When you want a changes in specific commit or specific sequence of commits we can use git’s feature which we call as cherry-pick

  • Now lets move to REL_1.1 branch and execute the cherry-pick command Preview Preview

  • Now lets move to the master branch

  • We have observed that HEAD always points to branch which in turn points to latest commit on the branch Preview

  • Now lets assume we checkout to a specific commit Preview

  • Now the head points to a commit id rather than branch. This state is called as Detached HEAD. Preview Preview

  • Now lets create a branch from master called as REL_1.2 and make some commits there Preview Preview Preview

  • Now lets assume there is an import change that is done on master Preview

  • Now this change has to be present in REL_1.2 branch also. If the REL_1.2 branch was created after this important change then it would be smooth. Preview

  • In Git this is possible to do with the help of rebase command. Rebase is git utilitiy that specializes in changing from one branch to other

    • Current Situation Preview
    • With Rebase we can do the following. Checkout to REL_1.2 branch Preview Preview Preview Preview
  • Lets make a commit Preview

  • In this commit we have made a typo and we want to correct it. Mistake is done in latest commit message.

git commit --amend

Preview Preview

  • Now lets make three commits
    • commit 1.2_4 => here we will make spelling mistake in commit message
    • commit 1.2_5 => here we will make spelling mistake in code
    • commit 1.2_6 => no errors Preview
  • If you want to rewrite history we can use interactive rebasing. git rebase -i <HEAD~Position>. In this we need to go back 3 postions
git rebase -i HEAD~3

Preview

  • We need to Reword commit 1.2_4 and ammend 1.2_5 and pick 1.2_6 Preview Preview Preview Preview
  • Now lets assume rather than having two commit 1.2_5 and 1.2_6 we would have it as one commit
git rebase -i HEAD~2

Preview Preview Preview

  • Current history Preview

  • Now lets try to delete the commit for 1.2.4

git rebase -i HEAD~2

Preview Preview *

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin