Mr_LinDowsMac
Mr_LinDowsMac

Reputation: 2702

Undo pushed changes to a file

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:

To this:

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?

Upvotes: 6

Views: 8192

Answers (1)

kaitoy
kaitoy

Reputation: 1675

  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.

Upvotes: 9

Related Questions