简体   繁体   English

如何从fork的原始项目创建一个干净的master分支?

[英]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. 好吧,所以我不小心将提交推送到了我的fork的master分支,并将该分支提交给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). 我现在需要创建另一个PR,但是无论如何我还是不知道可以基于未修改的master分支创建一个新分支(因为我不小心将提交提交到了那里)。 How can I create a branch based off the master branch of the forks origin project? 如何基于forks起源项目的master分支创建分支?

To clarify: I don't have a clean copy of the master branch to create another branch based off it. 需要说明的是:我没有master分支的完整副本,无法基于它创建另一个分支。 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). 转到您的master分支,并使用git log查看您的提交历史记录,并复制要返回的提交的哈希值(看起来像最近的一个)。

Use git checkout <hash> to get on that commit. 使用git checkout <hash>进行提交。 Then git branch <new branch name> to create a new branch based off the clean master branch. 然后git branch <new branch name>根据clean master分支创建一个新分支。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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