Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the "rebase and merge" option in Github create new commit SHAs? Is there an alternative?

Tags:

github

I like using the "rebase and merge" option for merging PRs in Github to avoid cluttering the commit history with merge commits.

But I've noticed the following behavior: (from Github's docs)

The rebase and merge behavior on GitHub deviates slightly from git rebase. Rebase and merge on GitHub will always update the committer information and create new commit SHAs, whereas git rebase outside of GitHub does not change the committer information when the rebase happens on top of an ancestor commit.

This seems strange to me since it's not how rebase works from the git CLI. Does anyone know why it behaves this way?

Ideally, I'd like to both a) avoid introducing merge commits and b) preserve the commit SHAs and tags from the feature branch. Is there a way to do this from the UI?

like image 668
Sam Hanes Avatar asked Jan 19 '18 22:01

Sam Hanes


People also ask

Does rebase create a new commit?

The Rebase Option But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch.

What does GitHub rebase and merge do?

When you select the Rebase and merge option on a pull request on GitHub.com, all commits from the topic branch (or head branch) are added onto the base branch individually without a merge commit. In that way, the rebase and merge behavior resembles a fast-forward merge by maintaining a linear project history.

Does a merge create a new commit?

Merge branchesGit creates a new commit (M) that is referred to as a merge commit that results from combining the changes from your feature branch and master from the point where the two branches diverged.

What changes for a commit when you rebase or merge?

When you do rebase a feature branch onto master, you move the base of the feature branch to master branch's ending point. Merging takes the contents of the feature branch and integrates it with the master branch. As a result, only the master branch is changed. The feature branch history remains same.


1 Answers

Your appreciation is correct, that's not how rebase works in git. The reason is in GitHub some options are poorly named:

  • Squash and Merge: Is similar to a squash and a rebase
  • Rebase and Merge: Is similar to a rebase with the --no-ff option (and even when the commit is up to date, a new commit will be introduced instead)

And if you are using the "GitHub Desktop" application you should have seen other unfamiliar names like "Sync" instead of "Pull"+"Merge"+"Push".

like image 196
Daniel Avatar answered Oct 13 '22 00:10

Daniel