say I have a commit "Added API endpoint", and I forgot to add documentation to that endpoint. I add that documentation, and I want those changes to be within that "Added API endpoint" commit.
My current workflow is:
git commit -m "Squash this please"
git rebase -i @\~2
pick AAA "Added API endpoint"
s BBB "Squash this please" # Changed the `pick` to `s` to squash into other commit
I do that quite often. Is there a better way to do this? A single command which squashes the currently staged changes into the last commit without the need for a new, temp commit?
I also tried the workflow of removing the last commit with git reset @~1, which puts its changes together with the new changes and then just recommiting with git commit -m "Added API endpoint", but this does not work well: If there are other unstaged changes I have to separate the "Added API endpoint" changes from them after the reset.
And this way feels less safe using reset instead of rebase.
Answer
As ElpieKay pointed out in a comment to this question: git commit --amend --no-edit does exactly that. Thank you!
(The duplicate flag is wrong imho)