Removing files from a pull request Warning: as confirmed by RCM in the comments: It does delete the file. It DOES NOT mean it will remove your changes to the file. It is quite deceptively worded, in my opinion.
Given that, there are multiple ways to remove a file from a Merge Request, such as: As you proposed, you can add a new commit to your source branch which effectively undoes the changes to the files you no longer wish to include. This could mean undoing the changes to existing tracked files, or deleting untracked files.
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:
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
You would want to amend the commit and then do a force push which will update the branch with the PR.
Here's how I recommend you do this:
git reset --soft HEAD^
or if it's a different commit, you would want to replace 'HEAD^' with the commit id)git commit -a -c ORIG_HEAD
The now that your branch has been updated, the Pull Request will include your changes.
Here's a link to Gits documentation where they have a pretty good example under Undo a commit and redo.
Switch to that branch where you want to revert the file.
This is the command for it.
Just need to choose the remote and branch where your file would be restored to
git checkout <remote>/<branch> -- <file_path_from_project_root_folder>.
In my case, it was
git checkout origin/master -- .github/workflows/ci.yml
Switch to the feature branch from which you created the pull request:
example : $ git checkout pull-request-branch
Overwrite the modified file(s) with the file in another branch:
$git checkout origin/master -- src/main/java/HelloWorld.java
Commit and push it to the remote:
$git commit -m "removed a modified file from PR"
$git push
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With