user33276346
user33276346

Reputation: 1759

Undo changes to a file pushed to GitHub that is part of a huge commit

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.

Upvotes: 0

Views: 1007

Answers (2)

Jeet Kumar
Jeet Kumar

Reputation: 547

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".

Upvotes: 1

David Sugar
David Sugar

Reputation: 1256

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.

Upvotes: 0

Related Questions