git 从拉取请求中删除修改过的文件

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

Remove a modified file from pull request

gitgithubversion-control

提问by jlee

I have 3 modified files (no new files) in a pull request at the moment.

我目前在拉取请求中有 3 个修改过的文件(没有新文件)。

I would like to remove one of those files from the pull request, so that the pull request only contains changes to two files and leaves the third in its original, untouched state.

我想从拉取请求中删除其中一个文件,以便拉取请求只包含对两个文件的更改,而将第三个文件保留在原始、未触及的状态。

I have tried a couple things (checking out the original version of the file, etc...) but it still shows as a changed file in the PR.

我已经尝试了几件事(检查文件的原始版本等...)但它仍然在 PR 中显示为已更改的文件。

Is there a solution to this?

这个问题有方法解决吗?

回答by Arpit Aggarwal

Switch to the branch from which you created the pull request:

切换到您从中创建拉取请求的分支:

$ git checkout pull-request-branch

Overwrite the modified file(s) with the file in another branch, let's consider it's master:

用另一个分支中的文件覆盖修改后的文件,让我们考虑它是master

git checkout origin/master -- src/main/java/HelloWorld.java

Commit and push it to the remote:

提交并推送到远程:

git commit -m "Removed a modified file from pull request"
git push origin pull-request-branch

回答by Keif Kraken

You would want to amend the commit and then do a force push which will update the branch with the PR.

您可能想要修改提交,然后执行强制推送,这将使用 PR 更新分支。

Here's how I recommend you do this:

以下是我建议您执行此操作的方法:

  1. Close the PR so that whomever is reviewing it doesn't pull it in until you've made your changes.
  2. Do a Soft reset to the commit before your unwanted change (if this is the last commit you can use git reset --soft HEAD^or if it's a different commit, you would want to replace 'HEAD^' with the commit id)
  3. Discard (or undo) any changes to the file that you didn't intend to update
  4. Make a new commit git commit -a -c ORIG_HEAD
  5. Force Push to your branch
  6. Re-Open Pull Request
  1. 关闭 PR,以便审核它的人在您做出更改之前不会将其拉入。
  2. 在不需要的更改之前对提交进行软重置(如果这是您可以使用的最后一次提交,git reset --soft HEAD^或者如果它是不同的提交,您需要用提交 ID 替换“HEAD^”)
  3. 放弃(或撤消)您不打算更新的文件的任何更改
  4. 进行新的提交 git commit -a -c ORIG_HEAD
  5. 强制推送到您的分支
  6. 重新打开拉取请求

The now that your branch has been updated, the Pull Request will include your changes.

现在您的分支已经更新,拉取请求将包含您的更改。

Here'sa link to Gits documentation where they have a pretty good example under Undo a commit and redo.

这是Gits 文档的链接,其中在Undo a commit 和 redo下有一个很好的示例。

回答by Chris Kitching

A pull request is just that: a request to merge one branch into another.

拉取请求就是:将一个分支合并到另一个分支的请求。

Your pull request doesn't "contain" anything, it's just a marker saying "please merge this branch into that one".

你的拉取请求不“包含”任何东西,它只是一个标记,说“请将这个分支合并到那个分支”。

The set of changes the PR shows in the web UI is just the changes between the target branch and your feature branch. To modify your pull request, you must modify your feature branch, probably with a force push to the feature branch.

PR 在 Web UI 中显示的更改集只是目标分支和您的功能分支之间的更改。要修改您的拉取请求,您必须修改您的功能分支,可能是强制推送到功能分支。

In your case, you'll probably want to amend your commit. Not sure about your exact situation, but some combination of interactive rebase and add -pshould sort you out.

在您的情况下,您可能想要修改您的提交。不确定您的确切情况,但是交互式 rebase 的某种组合add -p应该可以解决您的问题。