Nicolas Le Bot
Nicolas Le Bot

Reputation: 324

How to delete one line in a specific commit on github?

I'm currently working on a project with Github on a private repository.

I made a mistake last friday while pushing my code on my repo and I would like to delete 2 specifics lines (which contains sentsitive information)

I would like to know if it is possible to delete 2 lines (number 458 / 459 on a specific file) from the history, which would mean no trace at all from these information ?

I tried multiple stuff but it never worked and since I pushed more changes, so my commit is behind other.

Is there any way to do so ?

Thank's !

Upvotes: 1

Views: 1271

Answers (1)

Antonio Petricca
Antonio Petricca

Reputation: 10996

I suppose you have just pushed to the remote, so:

  1. Issue git log to retrieve the commit hash, which we will label as COMMIT_HASH.
  2. Issue git rebase -i COMMIT_HASH~1.
  3. The text editor will popup, so change the action to edit, save and close the editor.
  4. Make changes to your file(s).
  5. Issue git add --all.
  6. Issue git rebase --continue.
  7. Issue, IF ARE YOU SURE, git push --force.

Upvotes: 4

Related Questions