Everything you need to know to master git, Part 2, git revert, reset amend

How to undo a commit in Git when no one has pulled your changes from the repository? git reset

git reset will do this job for you, it has two option, hard and soft,

git reset –hard/ –soft <SOME-COMMIT>

1)Hard: this option will reset the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.

2)Soft: this option will leave the unstaged files in the working tree.


A Complete setup


some important note:

git add -A is equivalent to

Let’s continue our work:


The git reflog command records a chronological history of everything you have done in your local repository. Its full output might look like this:

C.txt and D.txt will remain (soft)

C.txt and D.txt will be deleted.

To see which files have been added and status:

Finally lets’ push changes by:


How to undo a push in Git when someone might have pulled your changes from the repository? git revert

If you’ve already pushed your changes and someone else pulled in those changes, you should not use git reset to undo changes, use git revert instead.


Let’s follow our work:


How to edit the git comment? git commit –amend -m “updated”

This will fix your most recent commit message



Pushing into the wrong branch

A very practical situation for the above command is pushing into the wrong branch,


Leave a Reply


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

Notify of