0

I'm trying to create a Pull Request in GitHub repository from one (example: develop) branch to master branch. The commit number in master branch is different from commit number in develop branch after PR completion.

Commit in develop branch:

enter image description here

Commit in master branch after PR completion:

enter image description here

Is there a way to make sure that the commit number won't change after PR completion? It stays the same as in develop branch?

user989988
  • 3,006
  • 7
  • 44
  • 91

2 Answers2

2

Yes. Make sure you are using the Create a merge commit option when accepting the pull request. This will merge the original commits unchanged.

On the other hand, the Squash and merge and Rebase and merge options will create new (but equivalent) commits with different hashes than the original commits.

Reference: https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/merging-a-pull-request


You asked in the comments:

I want only commits from develop to master on PR completion (same commit number, no extra commits). Is that possible?

In principle, this is possible in Git, by doing a fast-forward merge. However, as the above mentioned page states,

Pull requests are merged using the --no-ff option

so this is not possible by using the GitHub UI. As the maintainer of the source repository, you would have to manually do this by using the corresponding Git commands:

In your local copy of the repository,

  • fetch the new commits from the forked repository,
  • do the fast-forward merge (you can enforce it by using the --ff-only option for the git merge command),
  • and then push them to GitHub.

Further reading: What is the difference between `git merge` and `git merge --no-ff`?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
0

Generally speaking, there's no way to force a commit hash in Git. Unless the commits in develop apply "as-is" to master (i.e., no changes where committed to master since develop was branched out of it), when merging to master the commits would have to be rebased or merged, and you'll get a different commit hash.

Mureinik
  • 297,002
  • 52
  • 306
  • 350