DEV Community

Robertopaolo Ramirez
Robertopaolo Ramirez

Posted on

4 3

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
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.

recording

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

done

The result
The result

I hope I have helped you.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (2)

Collapse
 
spo0q profile image
spO0q • 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.

Collapse
 
ramirezmz profile image
Robertopaolo Ramirez

Thanks @jmau111

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more