4

I recently pushed a commit of changes of a project in a remote repository. I just figured out that one of the files that I usually don't commit its changes because it could contain sensitive information was included.

I want to undo the committed changes to that file (to the last previous state) without losing the changes of the commit in the other files.

From this:

  • Change FileSensitive -- ++
  • Change File1
  • Change File2
  • New File3
  • New File4

To this:

  • Change File1
  • Change File2
  • New File3
  • New File4

For the moment, only I have access to that repository, so there's no problem for rewriting history, so when I give access to that remote repository they won't see that sensitive info in history. So, how can I do that?

Mr_LinDowsMac
  • 2,644
  • 9
  • 56
  • 75
  • You can rebase your repo to the previous commit id..just follow this: http://stackoverflow.com/questions/3639115/reverting-to-a-specific-commit-based-on-commit-id-with-git – Hackerman Nov 10 '16 at 18:23
  • http://stackoverflow.com/questions/34519665/how-to-move-head-back-to-a-previous-location-detached-head/34519716#34519716 – CodeWizard Nov 10 '16 at 18:25

1 Answers1

6
  1. git reset --soft HEAD^ to undo the last commit keeping all changes made by the last commit in the index.
  2. git checkout HEAD <path to FileSensitive> to unstage and discard the change on FileSensitive. (Note the change on FileSensitive is lost by this command.)
  3. git commit and git push -f to update the remote repo.
Jose Paez
  • 747
  • 1
  • 11
  • 18
kaitoy
  • 1,545
  • 9
  • 16