Advanced Git and GitHub for DevOps (Part 1)
Git Branching
Git Revert and Reset
When we want to take a previous commit and add it as a new commit while maintaining the log, we use the revert command.
Step 1: Identify the prior commit:
Step2: Make a new commit using it:
Step 3: Let's create a fresh commit in which a file has been "accidentally" erased.
Git rebase?
What Does Git Merge Actually Do?
Task 1:
Add a text file called version01.txt inside the Devops/Git/ with “This is first feature of our application” written inside. This should be in a branch coming from master, [hint try git checkout -b dev], switch to dev branch (Make sure your commit message will reflect as "Added new feature"). [Hint use your knowledge of creating branches and Git commit command]
version01.txt should reflect at local repo first followed by Remote repo for review. [Hint use your knowledge of Git push and git pull commands here]
Add new commit in dev branch after adding below mentioned content in Devops/Git/version01.txt: While writing the file make sure you write these lines.
1st line>> This is the bug fix in development branch.
Commit this with message “Added feature2 in development branch"
2nd line>> This is gadbad code
Commit this with message “ Added feature3 in development branch"
3rd line>> This feature will gadbad everything from now.
Commit with message “ Added feature4 in development branch"
git log : Git log is a utility tool to review and read a history of everything that happens to a repository.
git log --oneline - The oneline option is used to display the output as one commit
per line.
Recommended by LinkedIn
Restore the file to a previous version where the content should be “This is the bug fix in development branch” [Hint use git revert or reset according to your knowledge]
git reset : Reset current HEAD to the specified state.
syntax : git reset <commit_ID>
In below image, if you will do git log you can see only two commits as the reset ones are deleted.
Task 2:
Demonstrate the concept of branches with 2 or more branches with screenshot.
git branch:
A branch is a version of the repository that diverges from the main working project. It is a feature available in most modern version control systems. A Git project can have more than one branch.
1.For show all branches:
git branch
2.Create a new branch:
git branch <branch_name>
3.For jumping into any specific branch:
git checkout <branch_name>
4.For deleting a branch:
git checkout -d <branch_name>
5. for creating and moving directly to that branch:
git checkout -b <branch_name>
git merge: Git merge is a command that allows developers to merge Git branches while the logs of commits on branches remain intact.
1.switch to master branch
2.git merge <branch_name> here branch_name is dev
3.check git log
git rebase:
Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow. The primary reason for rebasing is to maintain a linear project history.
Syntax : git rebase <base>
Thank you so much for your patience and for reading this far. If you have, please consider liking or supporting this article.