[git] Remove a modified file from pull request

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

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.

Is there a solution to this?

This question is related to git github version-control

The answer is


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.


Removing a file from pull request but not from your local repository.

  1. Go to your branch from where you created the request use the following commands

git checkout -- c:\temp..... next git checkout origin/master -- c:\temp... u replace origin/master with any other branch. Next git commit -m c:\temp..... Next git push origin

Note : no single quote or double quotes for the filepath


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.

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 -p should sort you out.


Questions with git tag:

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio? How to know the git username and email saved during configuration? How to add a new project to Github using VS Code git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 fatal: ambiguous argument 'origin': unknown revision or path not in the working tree HTTP Basic: Access denied fatal: Authentication failed npm notice created a lockfile as package-lock.json. You should commit this file Do I commit the package-lock.json file created by npm 5? Abort a Git Merge key_load_public: invalid format git - remote add origin vs remote set-url origin Visual Studio 2017 - Git failed with a fatal error Get git branch name in Jenkins Pipeline/Jenkinsfile Changing the git user inside Visual Studio Code How to compare different branches in Visual Studio Code Git checkout - switching back to HEAD Clear git local cache Deleting a local branch with Git Rebuild Docker container on file changes Cloning specific branch How to add chmod permissions to file in Git? Git copy changes from one branch to another Git merge with force overwrite Project vs Repository in GitHub How to add a file to the last commit in git? Getting permission denied (public key) on gitlab Delete commit on gitlab gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0] Remove a modified file from pull request Updates were rejected because the tip of your current branch is behind its remote counterpart Can't push to the heroku How to discard local changes and pull latest from GitHub repository In Visual Studio Code How do I merge between two local branches? error: RPC failed; curl transfer closed with outstanding read data remaining Change drive in git bash for windows Checkout Jenkins Pipeline Git SCM with credentials? How to fix git error: RPC failed; curl 56 GnuTLS Trying to pull files from my Github repository: "refusing to merge unrelated histories" Visual Studio Code how to resolve merge conflicts with git? merge one local branch into another local branch Can't push to remote branch, cannot be resolved to branch

Questions with github tag:

Does the target directory for a git clone have to match the repo name? Issue in installing php7.2-mcrypt How can I switch to another branch in git? How to draw checkbox or tick mark in GitHub Markdown table? How to add a new project to Github using VS Code git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 How to add empty spaces into MD markdown readme on GitHub? key_load_public: invalid format git - remote add origin vs remote set-url origin Cloning specific branch How to upload folders on GitHub Git merge with force overwrite Project vs Repository in GitHub Install specific branch from github using Npm gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0] Remove a modified file from pull request What do raw.githubusercontent.com URLs represent? How to discard local changes and pull latest from GitHub repository Trying to pull files from my Github repository: "refusing to merge unrelated histories" Git - remote: Repository not found git status (nothing to commit, working directory clean), however with changes commited When does Git refresh the list of remote branches? How to remove commits from a pull request github: server certificate verification failed Visual Studio Code always asking for git credentials What I can do to resolve "1 commit behind master"? How to overcome "'aclocal-1.15' is missing on your system" warning? How do I connect to my existing Git repository using Visual Studio Code? How to download a folder from github? Git: How to remove proxy Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Jenkins - how to build a specific branch There is no tracking information for the current branch How to rename a directory/folder on GitHub website? Git pull till a particular commit Git Clone from GitHub over https with two-factor authentication error: pathspec 'test-branch' did not match any file(s) known to git How can I install a package with go get? How can I clone a private GitLab repository? Git : fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists Copy a git repo without history GitHub: invalid username or password How to unmerge a Git merge? How to use private Github repo as npm dependency ! [rejected] master -> master (fetch first) How to remove a branch locally? How can I check out a GitHub pull request with git? How to resolve "git pull,fatal: unable to access 'https://github.com...\': Empty reply from server" Can you get the number of lines of code from a GitHub repository? Git: Installing Git in PATH with GitHub client for Windows

Questions with version-control tag:

How can I switch to another branch in git? Do I commit the package-lock.json file created by npm 5? Project vs Repository in GitHub Remove a modified file from pull request Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Git: How to squash all commits on branch git: updates were rejected because the remote contains work that you do not have locally Sourcetree - undo unpushed commits Cannot checkout, file is unmerged Git diff between current branch and master but not including unmerged master commits git push to specific branch How to use Git for Unity3D source control? Correctly ignore all files recursively under a specific folder except for a specific file type How to see the changes in a Git commit? Undo git update-index --assume-unchanged <file> Why do I need to explicitly push a new branch? What is the meaning of git reset --hard origin/master? Git - How to close commit editor? Warning: push.default is unset; its implicit value is changing in Git 2.0 SVN Repository on Google Drive or DropBox Should composer.lock be committed to version control? How can I make git accept a self signed certificate? Git clone without .git directory How do I check out a specific version of a submodule using 'git submodule'? How can I revert multiple Git commits (already pushed) to a published repository? Delete all local git branches Show history of a file? How to update a pull request from forked repo? How to amend older Git commit? Adding a collaborator to my free GitHub account? View a file in a different Git branch without changing branches Git: How to rebase to a specific commit? Why does 'git commit' not save my changes? How do you make Git work with IntelliJ? Merge a Branch into Trunk What's a good (free) visual merge tool for Git? (on windows) How to unstage large number of files without deleting the content How do I rename a local Git branch? Rebasing remote branches in Git How can I delete all Git branches which have been merged? Git On Custom SSH Port Get changes from master into branch in Git How can I get a list of Git branches, ordered by most recent commit? git diff between cloned and original remote repository gitx How do I get my 'Detached HEAD' commits back into master What is a tracking branch? What does "Git push non-fast-forward updates were rejected" mean? Download single files from GitHub How to output git log with the first line only? How to tag an older commit in Git?