Git reset hard Explained – Revert, Clean, tag

git reset command that is used to undo the local changes to the state of a Git repo. In a simple way to explain “reset” is the command when we want to move the repository back to a previous commit, Simply discarding any changes made after that commit.

Git reset

What is git reset vs revert?

something deferent “git revert” command that used to undo changes on a public branch, and “git reset” that used reserved for undoing changes on a private branch.
You can also understand of git revert as a tool for undoing committed changes, while git reset HEAD is for undoing uncommitted changes.

Table of Content :

1. What is git revert?

The “cat” is a utility command in Linux. that commonly use to print the content of a file and the cat command also allows us to write some texts into a file.
So, you will use ” cat >file name” command create a new file and write something “This is my first git file” and enter “ctrl+d” to save

# cat >resetfile

The “git add” command use adds a change in the working directory to the staging area. It’s inform to Git that you want to include updates to a particular file in the next commit.
Use “git add” command to add you code staging and showing status use “git status ” command.

# git add .
# git status

git status

What would happen if you ran the git reset?

git reset” is the command when we want to move the repository back to a previous commit, Simply discarding any changes made after that commit.

# git reset.
# git status

git reset

Now, you can rectify and require change something on “resetfile” file and again add that file to staging area.

2. Will git reset delete files?

# vi resetfile
# git add .

git reset –hard” command Reset from staging area and as well as delete from the working directory to match the most recent commit.

# git reset –hard ( full delete)

3. Git revert last commit ?

Note: you just run previous step to knowing git revert example command.

# cat >revertfile
# git add .
# git commit -m “this is first revert commit”
# git log –oneline

Now, you will over write something on that same file As, showing a wrong entry

# cat >>revertfile
Over write on revert

git revert

# git add .
# git commit -m “this over write or wrong commit”
# git log

git revert” command that used to undo changes on a public branch, You can also understand of git revert as a tool for undoing committed changes, while git reset HEAD is for undoing uncommitted changes.

# git revert < put commit Id>
Massage: Please ignore previous this commit
:wq

Use those to check the revert status.
You can see file has revert to previous state.

# ls
# cat restfiledemo
# git log –oneline

4. How do I clean up a git repository?

Use ” touch” command to Create multiple file to showing clean untrack file

# touch test1 test2 test3
# ls
# git status

Use ” git clean -n” to knowing untrack and up use file

# git clean -n

Use “git clean -f” command to remove all untrack file.

# git clean -f

5. what is git tag ?

Tags are ref’s that point to specific points in Git history. Tagging is generally used to highlight specific commit and easily identify.

# git log –oneline
# git tag -a important -m “this is very imp commit” <commit id>

Use those command to verify ” git tag” implementation.

# git tag
# git show important
# git log –oneline

6. How do you remove a git tag?

# git tag -d importtant
# git tag

7. What happens when you git clone?

# git clone <URL>

Summary

Git revert the changes that the related patches introduce, and record some new commits that record them. it’s very important command DevOps engineer to use development purpose.

Install Git in Linux | Git log, Push, Pull

Install Git in Linux Git log, Push, Pull
  • Install Git
  • Set up Git
  • Create working file
  • Check git log
  • Create GitHub Account
  • Generate and copy 2FA password
  • Push and Pull working data to Github account for use world wide.

How to git branch Create, Delete, Rename

How to git branch Create, Delete, Rename
  • create a code and commit
  • Create new branch
  • Code add and commit in new branch
  • Rename branch
  • Delete branch

Git Merge branch and Conflict – Step By Step

Git Merge branch and Conflict - Step By Step
  • Create branch
  • Git Merge branch create
  • Conflict branch

What is git stash & How to git stash Apply

5/5 - (2 votes)
Sharing Is Caring:

Leave a Comment