放弃Git针对拒绝的pull请求在Github上提交 [英] Abandoning Git commits on Github for rejected pull requests

查看:213
本文介绍了放弃Git针对拒绝的pull请求在Github上提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分叉了某人的项目并做了一些提交。我填写了一个拉取请求,但没有被接受(要么改变是不可取的,要么是作者改写功能以符合他的风格)。现在我坚持我的本地fork有一些额外的提交,永远不会进入上游。我可以退出变更集,但后来我有额外的两次提交,并且必须永远推送它们。这真是丑陋!



放弃这些提交的最好方法是没有人愿意并让我的分支返回上游跟踪?我知道我可以完全删除叉子并重新分叉它,但是这真的很笨拙,我会失去我正在做的其他工作。

解决方案

您可以将您的repo状态重置为先前的提交。首先找出你想要将你的repo重置为:

  git log 





git reset --hard< commit_hash>

如果您有分叉的远程回购,您可以将这些更改回推给它:

  git push -f< remote> <分支> 

您可能需要更改工作流程,以便将来更轻松。

b
$ b

当我发布回购协议并对其进行自己的更改时,我首先设置了两个远程控制台。一个远程将指向我的分叉回购(例如: origin ),并将另一个远程点添加到原始 original_repo )。所以我可能会有这样的东西:

  $ git remote 
origin
original_repo

code>

我创建了一个分支来完成我所有的工作,例如: feature 。在进行pull请求时,我从特性分支到 original_repo master 分支。如果拉请求被拒绝,就像你的例子,你可以放弃这个分支。如果你想进行更多的修改,只需从 master 创建另一个分支并使用它来处理。



我也不会提交或合并对 master 分支的任何本地更改。我只使用 master 分支与 original_repo master 分支。例如:

  git checkout master 
git fetch original_repo
git merge original_repo / master

这确保了 master 分支始终与原始仓库同步 master 分支。例如,如果拉取请求被接受并且被合并,当获取和合并发生时,本地 master 也将具有在原始回购中使用的所有批准代码。

基本上使用 master 与原始仓库的 master

I've forked someone's project and made some commits. I filled out a pull request, and it wasn't accepted (either the change was not desirable, or the author rewrote the functionality to be in line with "his style"). Now I'm stuck with my local fork having a few extra commits that will never get to go into upstream. I can back out the change sets, but then I have twice as many extra commits and will have to cart them around forever. It's just ugly!

What's the best way to abandon these commits that nobody wants and get my fork back to tracking upstream? I know I can delete the fork completely and re-fork it, but this is really heavy-handed and I'd lose any other work I'm doing.

解决方案

You can reset your repo state to an earlier commit. First figure out which commit you want to reset your repo to:

git log

To reset your repo to that state:

git reset --hard <commit_hash>

If you have a forked remote repo, you can push these changes back to it:

git push -f <remote> <branch>

You might want to change your workflow to make things easier in the future though.

When I fork a repo and am making my own changes to it, I first set up two remotes. One remote will point to my forked repo (ex: origin), and add another remote points to the original repo that was forked from (ex: original_repo). So I might have something like:

$ git remote
origin
original_repo

I create a branch to do all my work in, ex: feature. When making a pull request, I do it from the feature branch to the original_repo master branch. If the pull request is rejected, like your example, you can just abandon this branch. If you want to work on more modifications, just create another branch from master and use that to work in.

I also don't commit or merge any local changes to the master branch. I only use the master branch to sync up with the original_repo master branch. ex:

git checkout master
git fetch original_repo
git merge original_repo/master

This ensures the master branch is always synched up with the original repo's master branch. For example, if the pull request was accepted and merged in, when the fetch and merge happens, local master would also have all the 'approved' code used in the original repo.

Basically use master to sync up with the original repo's master and always branch from master when you want to make edits. Use those branches for your pull requests to the original repo.

这篇关于放弃Git针对拒绝的pull请求在Github上提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆