I have a set of commits, in reverse git log
order, in the same flat branch:
2018-01-01 AAAA1 "Some work 1" # Changes on directory
2018-06-01 SOME_OTHER_COMMIT "Unrelated commit in order"
2019-01-02 BBBB1 "Some work 2" # Changes on directory
.....
2018-01-01 AAAA2 "Some work 1" # Changes on file
2019-01-02 BBBB2 "Some work 2" # Changes on file
This is the result of moving some code with history from another repo. Directory moved out with git subtree split
while single file via git -am
, patch. Though it is unrelated to the original question while explaining the repository state
Now, I scripted the iteration of related commits. Grouping them by commit time.
E.g.,
for_each matching_commit_hash_pair
Rebase and squash "2018-01-01 AAAA1" + "2018-01-01 AAAA2" => "2018-01-01 AAAA-some-other-hash"
The question is, how this final non-interactive rebase (if rebase it is) would look like?
git rebase --onto AAAA1 ... just_single_AAAA2 commit <same_common_message>
Which is literally, moving sole AAAA2 commit to the past, right after AAAA1, keeping everything else the same
AAAA1
AAAA2
SOME_OTHER_COMMIT
BBBB1
BBBB2
With a final squash:
AAAA_SQUASHED
SOME_OTHER_COMMIT
BBBB_SQUASHED
While I didn't check the final squash of sequential-to-be commits, I'd expect it to be easy, same one-liner maybe