Git Deleting Commits from History

From NovaOrdis Knowledge Base
Revision as of 22:07, 30 July 2019 by Ovidiu (talk | contribs) (Created page with "=Internal= * Git Operations =Overview= This procedure is useful when a file containing sensitive information has been committed, and the sensitive information must be r...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Overview

This procedure is useful when a file containing sensitive information has been committed, and the sensitive information must be removed from repository, including from older commits. Deleting the file from the HEAD of the branch is insufficient, because the file can be accessed in oder commits. If the local branch was pushed remotely, the sensitive information is present on the remote branch as well. This procedure eliminates the commits locally and remotely:

git rebase -i HEAD~3

where 3 is the number of commits to be eliminated.

In the interactively edited file, change "pick" to "d" or "drop" for the commits to be deleted.

Save the file. There should be a message similar to:

Successfully rebased and updated refs/heads/master.

Alternatively, resolve conflicts.

To update the remote branch, do a:

git push --force

Filter Branch

Alternative method TODO, not tested.:

http://www-cs-students.stanford.edu/~blynn/gitmagic/ch05.html#_rewriting_history