DEV Community

Robertopaolo Ramirez
Robertopaolo Ramirez

Posted on

How to fix a commit?

To start this tutorial, I created a file and I'll use to test.

Start tutorial

Let's imagine that in the last command we wrote like this:

git commit -m "adding fils"
Enter fullscreen mode Exit fullscreen mode

To fix, simply type:

git commit -m "adding files" --amend
Enter fullscreen mode Exit fullscreen mode

Two important commands that git give us

git --hard and git soft

HARD = is usually used when we messed up the code and want to get everything back to how it was before you messed with it. It's an undo-like function, so be careful.

SOFT = On the other hand, we have Soft, which will remove the commits from our commit list without removing the changes from the commits.

git log

And in our case, we want to delete the last three commits.

git reset --soft HEAD~3
Enter fullscreen mode Exit fullscreen mode

And we can confirm by putting git log
confirmation git reset

We also confirm that the files are to be committed

Inteface experience Git by terminal

Another way (the most correct according to the documentation) is to give the following command:

git rebase -i HEAD~3
Enter fullscreen mode Exit fullscreen mode

git rebase -i

And we can (we must) change the command pick to squash

When recording, another screen will appear, informing what was done.


Also, it will ask us to put a decent message.


The result
The result

I hope I have helped you.

Top comments (2)

jmau111 profile image
jmau111⭐⭐⭐ • Edited

For anyone who wants to apply rebasing interactive, please ensure you do that BEFORE pushing anything to the remote repository. Otherwise, you'll have to force things which should be the very last resort.

ramirezmz profile image
Robertopaolo Ramirez

Thanks @jmau111