git – Remove a modified file from pull request

git – Remove a modified file from pull request

Switch to the branch from which you created the pull request:

n

$ git checkout pull-request-branchn

n

Overwrite the modified file(s) with the file in another branch, lets consider its master:

n

git checkout origin/master -- src/main/java/HelloWorld.javan

n

Commit and push it to the remote:

n

git commit -m Removed a modified file from pull requestngit push origin pull-request-branchn

You would want to amend the commit and then do a force push which will update the branch with the PR.

n

Heres how I recommend you do this:

n

    n

  1. Close the PR so that whomever is reviewing it doesnt pull it in until youve made your changes.
  2. n

  3. 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 its a different commit, you would want to replace HEAD^ with the commit id)
  4. n

  5. Discard (or undo) any changes to the file that you didnt intend to update
  6. n

  7. Make a new commit git commit -a -c ORIG_HEAD
  8. n

  9. Force Push to your branch
  10. n

  11. Re-Open Pull Request
  12. n

n

The now that your branch has been updated, the Pull Request will include your changes.

n

Heres a link to Gits documentation where they have a pretty good example under Undo a commit and redo.

git – Remove a modified file from pull request

Switch to that branch where you want to revert the file.

n

This is the command for it.

n

Just need to choose the remote and branch where your file would be restored to

n

git checkout <remote>/<branch> -- <file_path_from_project_root_folder>.n

n

In my case, it was

n

git checkout origin/master -- .github/workflows/ci.ymln

Leave a Reply

Your email address will not be published.