DevOps Classroom Series – 21/Nov/2021

Git reset hard vs soft vs mixed

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

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

  • 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
    • Even after you create the branch the HEAD will be pointing towards master i.e. working tree still represents master
    • To be in REL_1.0 branch we need to explicitly execute the command git checkout REL_1.0
    • Now lets make a commit in REL_1.0 branch
    • Now lets try to move to master branch git checkout master
    • 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
    • Now lets create a commit in REL_1.1
  • Now lets make two more commits on REL_1.0 branch

  • 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
    • 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
    • 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
    • So the classical merge will happen
    • Now lets come back to reality. The current history looks as shown below
    • Now to merge from REL_1.0 to master, move to Master and execute git merge REL_1.0
    • 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.
    • Now since we got the conflict we have two options
      • undo the merge
      • fix the merge:
        • current situation:
        • Open the conflicted files
        • After fixing conflicts and saving the files execute git add . && git commit
        • Now execute esc+:wq+Enter key combination
        • Now look at history
        • Our version graph

Leave a ReplyCancel reply

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

Please turn AdBlock off
Social Network Integration by Acurax Social Media Branding Company

Discover more from Direct DevOps from Quality Thought

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

Continue reading

Exit mobile version
%%footer%%