Change/modify branch that I want to merge from in GitHub pull request - github

I erroneously committed local changes on the "production" branch my organization uses for a project and opened a pull request to merge those changes (one simple commit) into the "development" branch (which is where changes should go in the period of time while they are not consolidated into a release).
Obviously, the "production" branch is hundreds of commits behind the "development" one. Is there a way I can change the pull request to be merging changes from another branch (the appropriate one, branching from "development") or my options are just to pull changes from "development" into my local branch involved in the PR or close the PR and open a new one?

Related

Azure master branch doesnt show the merged commits

We are using Azure DevOps, recently came across the issue when some of the commits that was stated to be completed and merged to the master branch dont show up in Repos history.
Azure master branch doesnt show the merged commits
It depends on the merge method you choose when you PR.
Azure Repos has several merge strategies, and by default, all of them are allowed. You can maintain a consistent branch history by enforcing a merge strategy for PR completion.
So, if you select the Squash merge, which is a merge option that allows you to condense the Git history of topic branches when you complete a pull request. Instead of each commit on the topic branch being added to the history of the default branch, a squash merge adds all the file changes to a single new commit on the default branch.
In this case, the commits that was stated to be completed and merged to the master branch dont show up in Repos history.
You could check the document Merge strategies and squash merge for some more details.

Update branch with rebase instead of merge

Is there any way to replace merge with rebase at GitHub PRs? I looked through protected branches settings but didn't find such option.
GitHub now (Feb. 2022) supports this:
More ways to keep your pull request branch up-to-date
The Update branch button on the pull request page lets you update your pull request's branch with the latest changes from the base branch.
This is useful for verifying your changes are compatible with the current version of the base branch before you merge.
Update your pull request branch by rebasing:
When your pull request's branch is out of date with the base branch, you now have the option to update it by rebasing on the latest version of the base branch.
Rebasing applies the changes from your branch onto the latest version of the base branch, resulting in a branch with a linear history since no merge commit is created.
To update by rebasing, click the drop down menu next to the Update Branch button, click Update with rebase, and then click Rebase branch.
Previously, Update branch performed a traditional merge that always resulted in a merge commit in your pull request branch. This option is still available, but now you have the choice.
Note: Because rebasing rewrites the history of the branch, if you are working with the branch locally, you will need to fetch it and do a hard reset to ensure your local branch matches the branch on GitHub.com.
Learn more about keeping your pull request in sync with the base branch.
I doubt github supports this, as you should never rebase a public branch. From the official git docs:
Rebasing (or any other form of rewriting) a branch that others have based work on is a bad idea: anyone downstream of it is forced to manually fix their history. This section explains how to do the fix from the downstream’s point of view. The real fix, however, would be to avoid rebasing the upstream in the first place.
The easiest solution would be to simply use a merge. If you don't like that for any reason, you could create a new branch from main, apply the desired changes (e.g. by using git cherry-pick, or git diff in conjunction with patch), and then delete the old branch and create a new PR. If you really want to use rebase, you can do so locally and force-push the branch, but again, that's a really bad idea as it falsifies history and breaks the branch for everybody else.

Change base branch of pull request and exclude merged commits

I have a pull request that is currently against the master branch and I want to change its base to a branch that is two commits behind master.
When I change the base branch in GitHub Enterprise the two commits that are not on master also get dragged into the pull request.
Is there a way to change the base branch but just have the commits that are actually in the pull request? I don't see any options other than the branch name, and my commit and one of the other commits touches the same file but not the same lines.

VSTS: Difference between default and compare branch

In my git repository I have three branches: master: default, dev: compare, and temp.
When I create a Pull Request from temp branch it defaults to dev as the target.
It is in contradiction with what Microsoft documentation says:
Change the default branch used to merge code into when your team
creates new pull requests. This is useful when you want to use a
branch other than master for the main line of development in your
repo.
Am I missing something?
For default branch, it helps you to treat the branch as default when cloning the git repo locally or creating a PR.
Such as if you treat master branch as default branch (by default), when you cloned the git repo locally, the local branch is master. And when you creating a PR, it will automatically treat master branch as the target branch.
For compare branch, it helps you to decide how many commits on the other branches are behind or ahead by comparing commits on other branches with the compare branch.
Such as for above example, develop branch is compare branch, and master branch and nn1 branch are compare with develop branch.
For comparing master branch with develop branch, there has 0 commits behind and 0 commit ahead (master branch same as develop branch). For comparing nn1 branch with develop branch, there are 3 commits behind and 48 commits ahead.
I did some quick tests in my VSTS tenant. It looks like the default branch of a new pull request is always the Compare branch, rather than the Default branch. So if you set your master branch as Compare branch, it should become to the default for new pull requests.
Not sure if it is bug of VSTS, or if they change the behavior of pull request without updating the doc.
Update:
I did some further research. It turned out that this change was introduced in a Oct 2016 feature roll out:
You can now set your compare branch to something other than the
default branch. This setting will be remembered on a per-user basis.
Pull requests and new branches created from the Branches page will be
based off the branch you set as the compare branch.
So the doc needs to be updated.

Can mercurial pull changes from forked repo into a new branch?

I have a project, biocommons/hgvs. A contributor forked the project, made some changes, and submitted a pull request. I'd like to make some minor changes to those commits, and I'd prefer to do so in a feature branch.
Is there a way to pull the PR commits into a new branch?
You cannot pull them in another branch in a sense how mercurial uses branch (as in named branch created by hg branch).
However, you simply can continue to work on top of your latest commit and later merge your head and the head created by the pull request, thus both, yours and their head being anonymous branches. (IMHO this is the beauty - every head can work on its own, no need to expressly branch or name things)
If you still want a name, you can stick a bookmarks onto the head of the pulled changes; they work very similar to 'full' branches except that they can be changed and moved.
If you really need and want the changesets to be in a named branch, then pull from the forked repository, create the named feature branch manually and use rebase or histedit to move the commits to the just created feature branch.