git 恢复更改并取消拉取请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21563845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git revert changes and cancel pull request
提问by px5x2
Unfortunately after years working with subversion, I am trying to warm up with git. The problem is as follows:
不幸的是,在使用 subversion 多年后,我正在尝试使用 git 热身。问题如下:
- i forked a remote project.
- pushed commits (which now i want to revert or simply vanish!) to my own remote.
- pull requested with my changes in above step.
- 我分叉了一个远程项目。
- 推送提交(现在我想恢复或干脆消失!)到我自己的遥控器。
- 拉请求与我在上述步骤中的更改。
Visually it looks like;
视觉上看起来像;
original project:
原项目:
A->B->C->D->E
my own remote fork (x,y,z are my commits to revert or delete if it's possible):
我自己的远程分支(x、y、z 是我对还原或删除的承诺,如果可能的话):
A->X->Y->Z->C->D->E
I want my forked remote to be as the same as the original remote. However After i tried reverting (with git revert [HASH]) my commits one by one and pushing those reverts to my own remote, It seems the pull request did not disappear.
我希望我的分叉遥控器与原始遥控器一样。但是,在我尝试恢复(使用 git revert [HASH])后,我的提交一一并将这些恢复推送到我自己的遥控器,看来拉取请求并没有消失。
The last thing would be remove my fork, and refork the original project, if i could not get a solution.
如果我找不到解决方案,最后一件事是删除我的叉子,并重新叉子原来的项目。
Any suggestions before doing that?
在这样做之前有什么建议吗?
采纳答案by janos
Assuming you have these two remotes defined in your local repo:
假设您在本地存储库中定义了这两个遥控器:
- origin: points to the original repo
- remote2: points to your own personal fork
- origin:指向原始仓库
- remote2:指向你自己的个人分叉
And you want to force update from origin/somebranch
to remote2/otherbranch
, you could do like this:
并且您想强制从origin/somebranch
to更新remote2/otherbranch
,您可以这样做:
# make sure you have up to date branch data locally
git fetch origin
git fetch remote2
# force push to remote2 from origin
git push remote2 origin/somebranch:otherbranch --force
To reset a local branch to the same state as a remote branch:
要将本地分支重置为与远程分支相同的状态:
git reset --hard origin/somebranch
回答by VonC
Note: in term of PR (GitHub Pull Request), you now (June 24th, 2014) can cancel a PR easily
(See also "Reverting a pull request"):
注意:在 PR(GitHub Pull Request)方面,您现在(2014 年 6 月 24 日)可以轻松取消 PR
(另请参阅“ Reverting a pull request”):
you can easily revert a pull request on GitHub by clicking Revert:
您可以通过单击 Revert 在 GitHub 上轻松地恢复拉取请求:
You'll be prompted to create a new pull request with the reverted changes:
系统会提示您使用已还原的更改创建新的拉取请求:
回答by VonC
Let's say you're on your master branch and want to erase some commits, you could git rebase -i A
to run and remove the unwanted commits from your local repo. (there are some good git rebase -i
informations on GitHub)
假设您在 master 分支上并想要删除一些提交,您可以git rebase -i A
运行并从本地存储库中删除不需要的提交。(GitHub 上有一些不错的git rebase -i
信息)
You can then git push --force origin master:master
to overwrite the remote master
branch with your local one. (warning, I'm nor responsible for the lost code resulting of this :P).
然后git push --force origin master:master
,您可以master
用本地分支覆盖远程分支。(警告,我不对由此导致的代码丢失负责:P)。
For your pull request, that is more a GitHub issue than a git one, I think you can easily close it on the webpage.
对于您的拉取请求,这更像是 GitHub 问题而不是 git 问题,我认为您可以在网页上轻松关闭它。
F.Y.I. git revert HASH
actually creates a commit that negates the patch of HASH, it do not really revert anything as you intended it ;)
仅供参考,git revert HASH
实际上创建了一个否定 HASH 补丁的提交,它并没有真正按照您的意图还原任何内容;)