简体   繁体   中英

How to create a clean master branch from the origin project of a fork?

Alright, so I accidentally pushed commits to the master branch of my fork, and submitted the branch for a PR.

I need to create another PR now, but I don't know anyway I can create a new branch based off a unmodified master branch (because I accidentally pushed commits there). How can I create a branch based off the master branch of the forks origin project?

To clarify: I don't have a clean copy of the master branch to create another branch based off it. What are some soultions I can use to fix this?

You can go to a previous commit and branch from there. Go to your master branch and use git log to see your commit history and copy the hash of the commit you want to go back to (one before your latest, it looks like).

Use git checkout <hash> to get on that commit. Then git branch <new branch name> to create a new branch based off the clean master branch.

You can create a new branch off a previous commit with

git checkout -b <new_branch_name> <commit hash>

However, it seems that the bigger problem is that you now have commits that are in master that shouldn't be there. Short of a force push to remove them, the only other option you have is to revert those commits. You mention that you are on your own fork, which may make force pushing a better option if no one else is also working on your fork. If you want to do that to fix your master, you can do

git reset --hard <commit hash to revert to>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM