Git Merge vs Rebase

merge
とrebase
は両方とも2つのブランチをマージするために使用されていますが、マージの仕方には違いがあります.Merge
git switch main
git merge feature
featureブランチが表示された後にプライマリブランチに変更がない場合、fast-forwardはfeatureブランチのcommitをプライマリブランチの最後尾に接続します.

それ以外の場合、プライマリブランチに変更がある場合は、変更が順番に再生された後に新しいマージコミットが生成されます.

新しいmerge commitが作成されても、すでに2つのブランチに存在するcommitは変更されません.
すべてのコミットが保持されるため、コミット履歴が複雑になる可能性があります.
Merge Squash
git switch main
git merge --squash feature
git commit

Rebase
git switch feature
git rebase main
featureブランチがプライマリブランチによって再作成されると、現在のプライマリブランチの末尾にfeatureブランチのcommitが作成されます.
commit履歴は書き換えられ、featureブランチのcommitのidが変更されます.

不要なmerge commitを生成し、履歴をクリーンアップしません.
featureブランチで作業する場合、mainが変更された場合は、mainの変更を事前にfeatureに反映するように再設定したほうがいいです.
他人と共有している、リモートレジストリにアップロードされているcommitは、相談なしに再公開しないでください.
マージ/リカバリの解除
git reflog
git reset --hard <commit-id>
Reference
この問題について(Git Merge vs Rebase), 我々は、より多くの情報をここで見つけました https://velog.io/@alexjlee/Git-Merge-vs-Rebaseテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol