Was working on a feature just now and noticed that I had forgotten to add a service that I thought was committed 2 commits ago. No problem, right? just git rebase -i
that sucker and put them into that commit!
$ git rebase -i <three refs ago>
OK. So I want to edit
the commit from 2 refs ago and leave the last commit alone.
pick: <last commit>
edit: <target commit>
I save... and now I can go in and add my files.
git add src/app/services/
git commit --amend
It is at this point that I want to note that I actually have been playing around with using zsh
's git plugin, which offers two aliases that are relevant to rebases:
-
grba
:git rebase --abort
-
grbc
:git rebase --continue
Also, what ended up happening at this point was this:
$ grba
Well, heck.
My commit was aborted, and those files that were amended to the rebased commit? Gone.
Thankfully PHPStorm's local history saved my code. Although in this particular case the service was all of 10 lines... but next time I shall have to be more careful when doing interactive rebases!
Update: See in comments below. The reflog
held the data! It was not gone...
Top comments (3)
$ git reflog
Should show you each rebase commit and annotate it (rebase).
Also
I completely forgot about the reflog!
You're right, the files I added are there:
git show --stat
of that commit shows the files are indeed there.Thank you!
Yeah, when you make a commit it is really hard to lose your work with Git. Know where to look or that something is missing can be hard though.