In my current branch, I've 2 commits which are not pushed yet.
mainlineBranch:
commit 2 - recent commit
commit 1
I've few code changes & want to amend only to commit 1 without deleting commit 2. Can someone please help me ?
git rebase --interactive helps you.
First, stash your uncommitted changes for later use (git stash). Your working directory should be clean now. Run git rebase -i HEAD~2 and your editor will pop up with the following content:
pick "commit 1"
pick "commit 2"
Change pick into edit for commit 1 and exit the editor. You can then git stash pop the changes onto the working tree, which should be at commit 1 now. Amend commit 1 with git commit --amend and continue the rebase with git rebase --continue. Assume conflicts are handled, you should now land on a new HEAD with a modified commit 1 and an identical commit 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With