Day-10 of DevOps Challenge: Elevating and Harnessing Advanced Git & GitHub Strategies

Akash RastogiAkash Rastogi
3 min read

Git Branching

A branch in version control systems like Git acts as a subdirectory where data is kept isolated from other branches, each having its own main directory, also its contain safe from other branches for any development and bug fixing etc.

Git Revert and Reset

These commands are powerful tools for managing commit history and project state in Git.

Git Revert:

Purpose**:** Revert changes by creating a new commit that undoes specific commits.

Usage**:** git revert <commit>

Effect**:** It creates a new commit that inverses the changes introduced by the specified commit, preserving the commit history.

Git Reset:

Purpose**:** Reset the current branch to a specific state.

Usage: git reset <commit>

Effect: Depending on the options used (--soft, --mixed, --hard), it moves the current branch pointer and optionally modifies the staging index and working directory to match the specified commit.

Git Rebase and Merge

These commands provide different purposes in managing branches and integrating changes in Git, but choice of this commands rebase and merge depends on the project's workflow and the desired outcome for the commit history.

Git Rebase:

Purpose: Reapply commits on top of another base tip.

Usage: git rebase <base>

Effect: It integrates changes from one branch onto another by moving or combining commits. This can lead to a cleaner history but requires caution when used on shared branches.

Git Merge:

Purpose: Join two or more development histories together.

Usage**:** git merge <branch>

Effect**:** It integrates changes from the specified branch into the current branch, preserving the commit history of both branches. This is suitable for combining work done in parallel branches.

I have performed some tasks that might help everyone on Advanced Git & GitHub Strategies

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, switch to dev branch ( Make sure your commit message will reflect as "Added new feature").

version01.txt should reflect at local repo first followed by Remote repo for review.

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

Restore the file to a previous version where the content should be “This is the bug fix in development branch.

We will be use both of scenarios Git revert and git reset

GIT REVERT

The error message we're encountering indicates that there are merge conflicts while attempting to revert the commit 28a8c7d. This typically happens when the changes introduced by the commit you're trying to revert (Added feature2 in development branch) conflict with the current state of version01.txt.

Open version01.txt in your text editor:

You'll see sections like: scss Copy code <<<<<<< HEAD Current content in version01.txt (conflict caused by the revert)

Content from commit 28a8c7d (Added feature2 in development branch)

28a8c7d... Added feature2 in development branch HEAD represents the current branch state (dev), and 28a8c7d represents the commit you're reverting. Resolve the conflicts:

Edit version01.txt to manually select which changes to keep. Remove the conflict markers (<<<<<<<, =======, >>>>>>>) and keep the content you want to restore. Stage the resolved file:

Git add version01.txt Complete the revert:

Once conflicts are resolved, continue the revert process:git revert --continue

GIT RESET

Demonstrate the concept of branches with 2 or more branches with screenshot and add some changes to dev branch and merge that branch in master as a practice try git rebase too, see what difference you get.

0
Subscribe to my newsletter

Read articles from Akash Rastogi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Akash Rastogi
Akash Rastogi