Add lines to the last commit

Kelvin Romero
1 min readMay 26, 2020

I’m currently working with RubyOnRails and Rubymine is my daily driver, very easy to commit just a few lines of code, but sometimes I forget some of them.

So, as you are not savage, you would also fix this, adding those forgotten lines to the previous commit. And here’s how you do it, start by patching the file with git add:

git add -p pathto/my_file.rb

Git’s gonna ask you what hunks of code you wanna stage, the options are: [y,n,q,a,d,e,?]? for now just know that

y - means stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones

And after deciding which hunks to stage, you can just commit without even change the commit message:

git commit --amend  --no-edit

Sources:

--

--