Github Unmerge a Commit and Push it to the right branch - github

Someone I work with pulled from the main branch changed a lot of code and merged it with a months old branch. Now a very important file is corrupted and has merging errors. How would you unmerge the commit and push the changes to the main branch instead? I'm not trying to save the old branch but the changes made before the merge.

Related

2 diff commit from same branch but diff merge?

I have created a branch and committed to it, got it reviewed and merged with main branch. Now when I try to push another change into another commit with the same branch now I see 2 commits on the branch and if I now merge, the first commit as well as the second will get merged? why is this happening?

Reseting branch for GitHub pull request

For one open source project, I opened pull request with commits in my branch. This PR stayed untouched for a few months.
Then, I did rebasing in that branch (because in the meantime it got conflict with master) and I messed something up so pull request got hundreds of commits from tens of contributors, and they are all added as "participants" to PR by GitHub. (I am not sure why GitHub is showing changes when those commits are from master, already merged)
I reverted rebasing in my local branch with git reset and it looks good, but I am wondering can I safely push that branch to origin? Will git push --force do the trick? If I do it, will those other commits be unaffected? What about participants to PR?
Note that this open source project is not mine, and that nobody else worked on my branch.
Will git push --force do the trick?
Yes, it will update/replace the PR commit history by your local one, and update the participants.
If you want to test it, you can push it to a new branch and create a PR from that new branch to see if the end-result PR looks OK.
And then delete that new PR, and force push to your original branch.

How do "reuse" a branch on Bitbucket / Sourcetree after merge

I was working on a branch of my Bitbucket repo (lets call it "frontend-dev"), which has now been merged with the master branch. I would like to branch again to make further changes, without creating a new branch. How do I branch and get back onto "frontend-dev".
I am using Sourcetree to manage version control.
Normally merging to master does not close or delete the branch. If there are changes in master since the merge from "frontend-dev", you can merge back to "frontend-dev". Either way, you can then simply switch your working copy to "frontend-dev" and continue developing.
Another question discusses what to do when you have closed or deleted the branch: Restore Merged Branch in Bitbucket Repo

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.

GitHub fork a repo from previous commit

I've found a repository on GitHub I would like to fork - but not the current version.
I want to fork the repo as it was quite a few commits back - is this possible? The repo has not marked any releases, so I'm not sure how to do this. I could obviously copy the code as it was in that commit, but I would prefer to fork, as then I get the link back to the original repo.
You can only fork the current repository.
You can reset the forked repository's master branch to an earlier commit though, making it look like as if you had forked it at that point.
See: How can I rollback a github repository to a specific commit?
If you reset every branch, it effectively resets your repository to an earlier state of the original repository (with exception of branch-independent data, like configuration, hooks etc which are not reset). Since it's possible that not all branches contain the commit from the master branch, you might need to look up commits by date for each branch, to reset them to the last commit before the commit from which you want to fork.
I was also unable to do this using github, but Sourcetree handled it perfectly.
Switched to the desired branch.
Found the commit that I wanted as the head of my new branch and right clicked.
Selected "branch."
My commit was already selected.
Name this new branch, create, and push.
Can also be done by selecting the "branch" button.
You then select the commit that you want as your new head, give it a name, and create it.