A few options for you:
Registration Limit
Not quite what you asked for, but maybe a good alternative, and much easier. This allows you to use git as usual, but it hides everything you donโt want to see (assuming the problem is the story cluttering your log and not the raw storage space. I think the merge crush in your branch wonโt prevent git from including all commits from the upstream if you first chose the upstream for the merge action.).
In this case, you should do a normal merge, but when registering, you add --first-parent to the command.
For example, without the option that I could have (suppose the โlarger sampleโ from 1 to 3 was actually much more significant)
$ git log --oneline 0e151bf Merge remote-tracking branch 'origin/master' into nosquash f578cbb sample more 3 7bc88cf sample more 2 682b412 sample more 1 fc6e1b3 Merge remote-tracking branch 'origin/master' 29ed293 More stuff 9577f30 my local change 018cb03 Another commit a5166b1 Initial
But, if I add --first-parent , it will clear up to this:
$ git log --oneline --first-parent 0e151bf Merge remote-tracking branch 'origin/master' fc6e1b3 Merge remote-tracking branch 'origin/master' 9577f30 my local change 018cb03 Another commit a5166b1 Initial
Pay attention to all the commits from the master after I forked ("my local change" is my diverging message) has disappeared. Only the commits I made appeared, including when I merged. If I used more efficient compilation messages during a merge, I might even know what a batch of changes is.
Replace story
This is for what you requested.
Using https://git-scm.com/book/en/v2/Git-Tools-Replace
What we will do here is squash the deleted history, replace their history with our compressed version from our point of view and combine the compressed version.
In my example repository, the changes that were added at the top, which I have not yet merged, were 682b412 "sample greater than 1" in origin / master (f578cbb "sample more 3") (although not so long for this example, pretend there are 50 commits or something in between). A.
The first thing I want is the local branch of the remote side:
git checkout -b squashing origin/master
Next, I want to quickly squash him
git reset --soft 682b412~ git commit -m "Squashed upstream"
Note the tilde character ~ . This causes our branch to be at the parent of the first commit in the range that we want to squash, and since we specified --soft , our index is still in the last commit in the range that we want to squash. The commit line results in one commit, consisting of what was from the first to the last, inclusive.
At this point, the origin / master and squashing branches have the same tree, but different stories.
Now we will tell git that when it sees links to the original origin / master commit, use a compressed commit instead. Using git log , I see that the new "Squashed upstream" commit is 1f0bc14, so we do:
git replace f578cbb 1f0bc14
In this case, your git will use a "compressed upstream" commit.
Let's go back to our original branch (if it was a "host")
git checkout master git merge f578cbb
It seems that combining the initial master (f578cbb) actually gets the contents of 1f0bc14, but registers it as having the parent SHA1 f578cbb
We no longer need a decoupling branch, so you can get rid of it.
Now, let's say, more features have been added upstream. In this simple example, in the upstream repository, the log can show this:
84f5044 new feature f578cbb sample more 3 7bc88cf sample more 2 682b412 sample more 1 29ed293 More stuff 018cb03 Another commit a5166b1 Initia
After we pick upstream, if we look at his journal from our repo, we see this instead:
84f5044 new feature f578cbb squashed upstream 29ed293 More stuff 018cb03 Another commit a5166b1 Initial
Pay attention to how, apparently, we also had a distribution story, and more importantly, SHA1 squeezed up shows the one used in the upstream history (for them, this is really โan assembly of more than 3โ).
So the merge continues to work as usual
git merge origin/master
But we do not have such a cluttered magazine:
4a9b5b7 Merge remote-tracking branch 'origin/master' for new feature 46843b5 Merge remote-tracking branch 'origin/master' 84f5044 new feature f578cbb squashed upstream fc6e1b3 Merge remote-tracking branch 'origin/master' 29ed293 More stuff 9577f30 my local change 018cb03 Another commit a5166b1 Initial
If the "new function" was fixed in the upstream, there were also a large number of commits, we could repeat this process to squeeze it down.