DevOps Classroom Series – 21/Nov/2021

Git reset hard vs soft vs mixed

  • Git reset –soft to fourth commit Preview
  • Git Reset hard vs soft vs mixed Preview

Git Branching

  • While building any application we might need parallel versions for multiple use cases

    • Experimenting with changes (POCs)
    • Handling multiple versions
    • Handling multiple customers
  • When in git repository you are always in a branch and the default branch is master.

  • To view all the branches in your local repo Preview

  • Lets create a new branch:

    • we can create the new branch using git branch <branch-name> a new branch will be create from the current HEAD and Branch (master)
    • Lets create a branch called as REL_1.0 => git branch REL_1.0 Preview
    • Even after you create the branch the HEAD will be pointing towards master i.e. working tree still represents master Preview
    • To be in REL_1.0 branch we need to explicitly execute the command git checkout REL_1.0 Preview Preview
    • Now lets make a commit in REL_1.0 branch Preview Preview
    • Now lets try to move to master branch git checkout master Preview Preview
    • If we want to create a new branch and move the HEAD to the new branch then we need to execute git checkout -b <new-branch-name>. SO Lets create REL_1.1 and move the head to the REL_1.1 Preview
    • Now lets create a commit in REL_1.1 Preview Preview
  • Now lets make two more commits on REL_1.0 branch Preview Preview

  • To view the history lets use this command git log --graph --decorate --pretty=oneline --abbrev-commit

  • Merging Branches:

    • Now lets assume that our work in REL_1.0 branch is done and we want to bring back the changes to master branch
    • The current state of the branches are as shown below Preview
    • Now if we want the history or all the commits done in REL_1.0 also to be included in master (bring back all the changes), then if my master branch looks at the latest commit of REL_1.0 branch then we will still have two branches (master, REL_1.0) and the history will be retained and all the changes also will be retained Preview
    • This kind of scenario is called as Fast-Forward Merge
    • Now lets assume our master branch is as shown below, in this case Fast-Forward will not work Preview
    • So the classical merge will happen Preview
    • Now lets come back to reality. The current history looks as shown below Preview
    • Now to merge from REL_1.0 to master, move to Master and execute git merge REL_1.0 Preview Preview
    • Now lets assume we have done the completed the change in REL_1.1 branch and we need to bring back the changes to master, so we need to merge the changes.
    • When we merge the code, we might get merge conflicts, It is upto the user who is merging to resolve conflicts. Preview
    • Now since we got the conflict we have two options
      • undo the merge Preview
      • fix the merge:
        • current situation: Preview
        • Open the conflicted files Preview Preview
        • After fixing conflicts and saving the files execute git add . && git commit Preview
        • Now execute esc+:wq+Enter key combination
        • Now look at history Preview
        • Our version graph Preview

Leave a Reply

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

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube