git log
and
git revert
In this quick blog, we will see how to check the current branch's
commits using the terminal only. This method can be highly
beneficial when checking whether you successfully merged or rebased
your branch. Rest assured, I will also guide you through the process
of reverting a commit that was pushed accidentally, making it a
breeze.
The commands we are going to explain are
git log
and
git revert
.
git log
git log
is very
simple; It lets the user check the current branch commits. To use
it, open the terminal, navigate to your repo, and do git log. This
command is what we are going to use to revert bad commits.
git revert
From its name,
git revert
allows
you to revert a bad commit/s in a single line. Let's say you have
the below branch where the alphabets refer to the commits (hashes).
A---B---C---D main branch
D is the commit you wish to revert; all you have to do is run git revert D (where D is the commit hash), then push, and that's it!
git clone https://github.com/MumenTayyem/github-basics.git
git checkout -b {your-name}
git push origin {your-name}
git add .
git commit -m "I'm testing revert"
git push origin {your-name}
git log
git push origin {your-name}
In this blog, you learn how to see your branch's current commits in the terminal and the quickest way to revert bad commits! I hope this is helpful for you!