Remove a file from a Git Pull Request
You could 'unstage' a particular file with git reset
and then amend the original commit:
git reset HEAD^ /path/to/file
git commit --amend --no-edit
git push -f
This will not affect the version of the file in your working copy.
Alternatively, if you want to remove multiple files, you can reset the branch's head to the previous commit and create a new one:
git reset HEAD^ # move the tip of the branch to the previous commit
git commit -C ORIG_HEAD file1 file2 [...] # list the required files
git push -f
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