#Day 16 Git Branch  Revert/Reset:

#Day 16 Git Branch Revert/Reset:

Table of contents

GIT BRANCH:

Git branching is a powerful feature of the Git version control system that allows you to work on multiple versions of your code simultaneously. A branch is a copy of your code that you can modify independently of other branches. This allows you to experiment with new features, fix bugs, or work on different aspects of your project without affecting the main branch. and they make it easy to switch between different versions of your code, manage merge conflicts, and collaborate with others on a project. You can create a new branch, switch between existing branches, and merge branches to bring changes from one branch into another. The main branch in Git is typically called "master."

GIT REVERT/GIT RESET:

In Git, the revert command is used to undo the changes made in a specific commit. When you revert a commit, Git creates a new commit that undoes the changes made in the original commit. The original commit is not deleted, but its changes are undone in a new commit.

The reset command, on the other hand, discards commits, moving the branch pointer to a previous commit and destroying the commits in the branch that come after it. This is a more destructive operation, as it permanently removes commits from the branch's history.

In reset --soft:The file will be change and Changes will not be wiped out.

In reset --hard: The file will be changed back and Changes will be wiped out.

In reset --mixed :

Tasks

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

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

Restore the file to a previous version where the content should be “This is the bug fix in the development branch” [Hint use git revert or reset according to your knowledge]

2.Demonstrate the concept of branches with 2 or more branches.

When you create a new project in Git, it creates a default branch called "master." The master branch is the main branch of the repository, and it is where all development begins. As you make changes to the project, you can create new branches to test different ideas or to work on different features.

For example, you might create a branch called "feature1" to work on a new feature for your project. You can continue to make changes to this branch, and when the feature is complete, you can merge it back into the master branch.

Add some changes to dev branch and merge that branch in master.