My team was working on a long running feature branch which has hundreds of commits now and now i need to merge it into master for production release.
I do not want to have that many commits in that branch since many commits were done for doing bug fixes and are changing only couple of lines per commit.
On the PR creation page on Github it limits the commits shown at 250.
From Github - "This comparison is big! We’re only showing the most recent 250 commits"
Hence, I decided to compress the history in a way that a set of sequential commits from an author gets squashed into a single commit.
E.g say we have commits like : A - A - A - B - B - A - C - D - D - B- B -A
from authors A, B, C and D then the resulting commit log will have A(3) - B
(2) - A - C - D(2) - B
(2) - A where X`(N) is squashed commit of N commits from author X.
Edit: I understand that this will need a script and i am looking for the same. I do not want to go through interactive rebase to do the same.
Console:
git log --format="p|%h|%an|%s" --no-merges -n 190 | tail -r > commits.txt
PHP:
$fp = fopen("./commits.txt", "r");
$commits = array();
$previous_author = '';
while (($line = fgets($fp)) !== FALSE) {
list($mode, $sha, $current_author, $subject) = explode('|', $line);
if ($previous_author == '' || $previous_author !== $current_author) {
$previous_author = $current_author;
}
else {
$mode = 'f';
}
$output[] = implode(' ', array($mode, $sha, $subject));
}
fclose($fp);
print implode(' ', $output);
Console:
git rebase -i HEAD~190
In interactive editor, deleted everything and pasted the output of the php script above. I could achieve the intended results.