Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a modified file from pull request

People also ask

What happens if I delete file from pull request?

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.

How do you delete a file from a merge request?

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:

  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

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