0

I created a commit that includes changes to several files, which are ok, except for one. This file was already in Github and my PC but I wasn't supposed to change it in GitHub (only in my PC if I needed to do so). So when I was creating a pull request, in the previous step where it shows you the changes, it shows the changes.

I tried to fix this with git revert -n [hash of the commit] but it reverts everything and I just need this file to not show up as changed in the GitHub pull request.

user33276346
  • 1,501
  • 1
  • 19
  • 38
  • possible duplicate of https://stackoverflow.com/questions/215718/how-can-i-reset-or-revert-a-file-to-a-specific-revision – LuVu Oct 31 '19 at 17:42

2 Answers2

1

Possbile Solution: You should use reset command of git.

Please follow the below steps:

  1. git reset --mixed < commit hash >
  2. git reset < you file name that you dont want to include in your commit >
  3. git commit -m "latest commit exclude one file".
Jeet Kumar
  • 555
  • 3
  • 12
0

To revert one file from a commit:

<on your branch>
git revert -n [hash of the commit]
git reset -- <list of files you don't want to revert>
git commit
git push

The git reset <file> command removes or resets files in the staging area so that they will not be committed.

Another way to revert a single file is:

<on your branch>
git checkout [hash of the commit]:[filename]
git add [filename]
git commit
git push

Once you've pushed your changes onto your remote, Github branch, your pull request will be updated.

David Sugar
  • 1,042
  • 6
  • 8