Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a file from a Git Pull Request

Tags:

git

github

I have added a local changes to an existing file into my PR by mistake. I want to revert only this file without deleting this file locally. I just want that it doesn't show up in the Pull Request. I don't want to create new branch as many people have commented on other files in this PR.

like image 239
overflower Avatar asked Aug 03 '16 12:08

overflower


People also ask

How do I exclude certain files from a pull request?

To exclude certain files from appearing in pull requests: In the repository containing the pull request, click Repository settings > Excluded files in the Pull Requests section. In the Patterns field, enter patterns to exclude from pull request diff views. Click Save.

What does deleting a file from a pull request do?

It does delete the file. It DOES NOT mean it will remove your changes to the file.

How do I delete a specific 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.


1 Answers

If you updated a file that already existed and want to remove it from the PR:

Assume you're working on a branch off of staging, and you PR'd a file named validate_model.py.

To remove this file from the PR and revert its changes, simply do:

git checkout staging -- validate_model.py 
like image 187
Jared Wilber Avatar answered Sep 28 '22 23:09

Jared Wilber