git 从 GitHub 上的拉取请求中删除文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9498201/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:04:11  来源:igfitidea点击:

Delete file from Pull Request on GitHub

gitgithubpull-request

提问by LightNight

I have make pull request on git (with "xcodeproj/project.pbxproj" file - my fault), so can I delete this file from created Pull Request? Thanks..

我已经在 git 上提出了拉取请求(使用“xcodeproj/project.pbxproj”文件 - 我的错),所以我可以从创建的拉取请求中删除这个文件吗?谢谢..

采纳答案by Xion

  • Make a commit that deletes this file and push it.
  • Go to your fork's Github page and click Pull Requestagain. You will get a message stating that you already have a pull request, and that you can adjust the commit range for it.
  • Include your new commit (with the deletion).
  • 进行删除此文件并推送它的提交。
  • 转到您的 fork 的 Github 页面,然后再次单击Pull Request。您将收到一条消息,说明您已经有一个拉取请求,并且您可以为其调整提交范围。
  • 包括您的新提交(包括删除)。

The offending file will still be in the changesets to be merged, mind you, so if it contains sensitive data it's best to close the pull request and wipe out the file from your fork's repository first. Github help describeshow to do that.

请注意,有问题的文件仍将在要合并的变更集中,因此如果它包含敏感数据,最好先关闭拉取请求并从您的复刻存储库中清除该文件。Github 帮助描述了如何做到这一点。

回答by Albert Abdonor

You probably will merge this pull request on master, so you can checkout just this specific file again, from master, on your branch, just type:

你可能会在 master 上合并这个 pull request,所以你可以再次检出这个特定的文件,从 master,在你的分支上,只需输入:

git checkout master -- xcodeproj/project.pbxproj
git commit -m "removing a file from PR"
git push origin {YOUR BRANCH}

回答by nulltoken

Another solution would be to

另一种解决方案是

  • Locally rewriteyour commit(s) by removing the file, using amendor rebasegit features
  • Force pushyour branch toward your GitHub repository
  • 通过删除文件,使用amendrebasegit 功能在本地重写您的提交
  • 强制将您的分支送到您的 GitHub 存储库

This will update the pull request by only displaying your refreshed commit(s).

这将通过仅显示您刷新的提交来更新拉取请求。

回答by VonC

New approach, since July 2018:

新方法,自 2018 年 7 月起:

Removing files from a pull request

Previously, if you wanted to use GitHub to remove files from a pull request, you'd need to switch to the pull request branch and look for the individual file to delete it.

Now, if you have write permission, you can click on the ‘trash' icon for a file right in the pull request's “Files changed” view to make a commit and remove it.

从拉取请求中删除文件

以前,如果您想使用 GitHub 从拉取请求中删除文件,您需要切换到拉取请求分支并查找单个文件以将其删除。

现在,如果您有写权限,您可以在拉取请求的“文件已更改”视图中单击文件的“垃圾箱”图标以进行提交并删除它

回答by singingsingh

CAUSION : Will delete local file also. Suitable when you pushed an auto generated file.

原因:也会删除本地文件。适用于推送自动生成的文件。

git rm <path to file>

回答by Annette Ambriz

To remove a file from your PR:

要从 PR 中删除文件:

git rm path/toFile/youwantRemovedOffyour/PR
git commit -a
git push

To remove a directory from your PR:

要从 PR 中删除目录:

git rm -r path/toFiles/youwantRemovedOffyour/PR
git commit -a
git push

回答by Arun GK

If all you want to do is just remove(delete) the changeset of a file that is already a part of the pull request, currently you can't do that via the web UI. You have to update the file locally and do a git push to the PR.

如果您只想移除(删除)已经是拉取请求一部分的文件的变更集,那么目前您无法通过 Web UI 执行此操作。您必须在本地更新文件并向 PR 执行 git push。