DEV Community

Cover image for Amend a specific commit
Sara Ounissi
Sara Ounissi

Posted on • Updated on • Originally published at thetrendycoder.com

Amend a specific commit

Here is my situation: I had to do a dev that I cut into two different commits. I asked for a review from my team and got feedback on the first commit. I realized I didn’t know how to amend a commit that wasn’t the last one in the git history. I really didn’t want to create a specific commit for this fix, it wouldn’t be clean. I wanted to amend the first commit to have a clean git history. Here is the process I followed to be able to do that successfully :

Select the number of your commit, here we want to modify the commit bac653ad. So I had to run :

git rebase --interactive 'bbc643cd^'
Enter fullscreen mode Exit fullscreen mode

In the default editor, you will have this kind of view :

pick bac653ad fix: first commit 
pick ac39035 feat: second commit
Enter fullscreen mode Exit fullscreen mode

Change the name of the commit if you want, or keep it how it is and save. Then run :

git rebase --continue
Enter fullscreen mode Exit fullscreen mode

Now you can push force :

git push --force
Enter fullscreen mode Exit fullscreen mode

Your changes should have been added to the specific commit you wanted.

Shut out to StackOverflow for helping me solve this problem!

Top comments (0)