'Git how to merge without a merge commit, but preserving hashes (to have a straight graph line in the git log)

So I have 2 branches - develop_1 and develop_2.
The first one needs to be merged into the second (let's say there are 3 commits in develop_1 which needs to be in develop_2).

I know there are merging strategies like merge and rebase.
Merge will preserve commit hashes but will create another merge commit and the git log won't be so clean in this case.
Rebase will make the git graph beautiful but will change commit hashes, so next time when I'll compare these two branches, it will still show the difference (while code changes actually are merged and actually develop_1 branch is fully merged into develop_2).

I tried to cherry-pick needed commits - hashes are changed. Patch also changes hashes.

Is there a way to do this clean - don't create a merge commit, have a straight line in the git graph, and have the git system (Github) don't show a difference between branches in the future?



Solution 1:[1]

If the branches can be fast-forwarded then you'll get a clean history when doing a git merge. Otherwise, in the case where it cannot be done, you are out of luck, there is no way to not change the hashes while keeping a linear history. As to create the linear history you need to rewrite part of the history of the branch you want to merge into.

If I understand correctly the way to go about it, is to rebase develop_2 on top of develop_1

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Girgias