0

I have made changes in my branch and then performed a git push and also created PR (pull request).

Now the PR reviewer instructed me to "exclude your change to this file".

This message referred to 3 different files. He also told me to remove one folder which I have added from commit.

So what is the best and easy way to do this, to to exclude files and folder from an existing PR?

Simona
  • 279
  • 1
  • 8
Nic
  • 439
  • 4
  • 14

1 Answers1

2

You cannot change the commit that was already made. What you can do is to commit further changes that will undo the changes that are no longer needed.

The best way to do this depends on:

  • If you are keeping most of the changes made to the files and are only undoing changes made to a few lines, then just edit the files to revert those lines to their previous states, commit the changes and push to the git server.
  • If you are undoing all of the changes made to the files run git checkout origin/master path-to-your-file to revert your local version to the version on the main git server, and then commit and push these changes (see this answer for more).
  • If you are undoing most of the changes but keeping some small part, make a copy of the file in notepad or some other local program, checkout the version from origin/master (see previous step) and then copy in the changes that you want to keep.
  • If this seems too complicated, simply branch off of the main branch on origin in a new branch, and cherry-pick the changes that you do want to bring over, and use this to create a new PR.

As far as changes to a folder - if you remove all changes to files in a folder and commit your reversions, then the folder change should also go away.

Simona
  • 279
  • 1
  • 8
  • I tried git --checkout origin/master path-to-your-file, but getting this error unknown option --checkout – Nic Jul 20 '21 at 09:34
  • @Nic sorry, it shouldn't have the `--` double-dashes. I corrected this in my answer. – Simona Jul 20 '21 at 09:48