Git rebase non-interactive for last two commits - write a batch file
batch-file, git, rebase
Solution
The idea would be to do a:
git reset --soft @~ # reset HEAD, preserve current working tree and index
git commit --amend -m "squash HEAD and HEAD~"
That doesn't address the commit messages though: the one from `ORIG_HEAD` would be lost. torek addresses that in the comments.
If you have multiple commits to squash (since `origin/master`), what you can do is (supposing you don't have any work in progress):
echo "squash everything since origin/master" > /tmp/msg
git log --format=%B origin/master~3.. >> /tmp/msg
git reset --soft origin/master
git commit -F /tmp/msg
This time, you don't amend the commit you reset to (since origin/master was already pushed), but you create a new one.
Problem
Please help me to write a batch file for `git rebase` which unites two last commits: `HEAD` and `HEAD~1` in current branch into one without using interactive editor. Assume that both commits have single parent and are not pushed yet. ``` a683ec1 Not pushed 2 c7b480a Not pushed 1 f0e81fb Pushed ``` I want to leave "Pushed" commit and one commit behind it that will contain "Not pushed 1" + "Not pushed 2" in a final state of "Not pushed 2".