简体   繁体   English

如何在 github 上的特定提交中删除一行?

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

I'm currently working on a project with Github on a private repository.我目前正在私有存储库上使用 Github 开展一个项目。

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)上周五我在我的仓库中推送我的代码时犯了一个错误,我想删除 2 个具体行(其中包含敏感信息)

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?我想知道是否可以从历史记录中删除 2 行(特定文件上的编号 458 / 459),这意味着这些信息根本没有任何痕迹?

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 !谢谢 !

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.发出git log以检索提交 hash,我们将 label 作为 COMMIT_HASH。
  2. Issue git rebase -i COMMIT_HASH~1 .问题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 .问题git add --all
  6. Issue git rebase --continue .问题git rebase --continue
  7. Issue, IF ARE YOU SURE , git push --force .问题,如果你确定, git push --force

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM