Github提交密码信息后补救措施

新建一个repo,在添加.gitignore文件之前,把仓库push到github,虽然数据库密码配置文件可以删除,但是git的commit记录依旧在。根据github官方的建议,可以使用bfg来删除commit记录

使用BFG工具

BFG Repo-Cleaner是github官方推荐的工具,用于删除敏感信息数据文件

  • 删除敏感信息文件

    config.ini是MySQL数据的链接配置文件,前面已经提交过一次。此时使用BFG工具进行删除

java -jar .\bfg-1.14.0.jar --delete-files config.ini

Using repo : D:\bench\.git

Found 33 objects to protect
Found 3 commit-pointing refs : HEAD, refs/heads/master, refs/remotes/origin/master

Protected commits
-----------------

These are your protected commits, and so their contents will NOT be altered:

 * commit f8efb82f (protected by 'HEAD')

Cleaning
--------

Found 3 commits
Cleaning commits:       100% (3/3)
Cleaning commits completed in 540 ms.

Updating 2 Refs
---------------

        Ref                          Before     After
        ------------------------------------------------
        refs/heads/master          | f8efb82f | aee89bd8
        refs/remotes/origin/master | f8efb82f | aee89bd8

Updating references:    100% (2/2)
...Ref update completed in 39 ms.


        Earliest      Latest
        |                  |
           D     D      m

        D = dirty commits (file tree fixed)
        m = modified commits (commit message or parents changed)

                                Before     After
        -------------------------------------------
        First modified commit | 8678605e | ed92ad02
        Last dirty commit     | b3d21fd9 | f09c8f34

Deleted files

        Filename     Git id
        config.ini | ebc00fef (70 B )

In total, 5 object ids were changed. Full details are logged here:
  • 强制push

    删除文件后,必须push只github仓库 我使用的是Pycharm,强制push,需要在push对话框,选择Force push

git push --force
  • 提示:

    如果在pycharm中无法选中Force push,需要进行配置: File-->Settings-->Version Control-->Git-->Push-->Protected branches,删除文本框中的master,main

bytetoy.cn

results matching ""

    No results matching ""

    results matching ""

      No results matching ""