I have a Git repository with the following git log
information in master
:
commit 23c5565d156266f3e26943d0811abaa88f7957a1 (HEAD -> master)
Fourth commit.
commit 92c0d491c3fd537a06876d1c0fc69c27ebf3e935
Third commit.
commit 67d604623f1b7fd8492f42edd6aebda83b075173
Second commit.
commit 11ef1cc228c27c87771dbc1a6a3fa98b7a605fa5
First commit.
commit 946f4fb2a02042f450090414eee6324799eb35df
Initial commit
Using libgit2
I want to perform a rebase where I squash the top four commits together (23c556
- 11ef1
) and leave the initial commit intact. I aim to solve this by rebasing the master
branch onto commit 946f4
, picking the first commit, and then squashing the other three. This would be similar to git rebase -i HEAD~4
with the squash command on the last three commits.
This is pseudocode that I wrote to try and solve this:
git_rebase_init( &rebase, m_repository, branch, nullptr, initialCommit, &opts );
bool shouldSquash = false;
git_oid rebaseOID = {{0}};
while ( git_rebase_next( &op, rebase ) == GIT_OK )
{
if ( shouldSquash )
{
op->type = GIT_REBASE_OPERATION_SQUASH;
}
else
{
op->type = GIT_REBASE_OPERATION_PICK;
shouldSquash = true;
}
git_signature * author = generateSignature();
if ( !author ) return false;
git_rebase_commit( &rebaseOID, rebase, author, author, nullptr, nullptr );
}
git_rebase_finish( rebase, nullptr );
Unfortunately while the rebase completes, none of the commits are squashed. They each appear as they did in the log above except they have different commit hashes.