经常更新gitea
开始几次都没事, 退掉正在运行的gitea, 更换新版本, 重新运行gitea.
git客户端提交, push都正常.
今天换了 gitea-1.16.8-gogit-windows-4.0-amd64.exe.
因为时间久了, 整错地方了. 没有放到库目录下, 就开始运行.
结果发现迁出的库, 无法push了.
登录gitea本地管理网页(http://localhost:3000), 发现自己忘记密码, 甚至不确定用户名是啥. 这个有点严重…
后来发现自己将 gitea-1.16.8-gogit-windows-4.0-amd64.exe 摆错地方了, 退掉 gitea, 将 gitea-1.16.8-gogit-windows-4.0-amd64.exe摆到 本库git库目录下重新运行后, 还是无法登录管理网页(用户名和口令不对, 自己又想不起来).
这咋弄, 有点严重啊.
先去查网上资料, 如何重置gitea系统的用户名和口令, 资料比较简单, 不好使, 不知所以然. 资料上没说他们用的gitea版本, 也没说那些恢复的命令行哪里来的. 如果是这样的话, 如果用的gitea版本和他们不一样, 就不好使了.
win10-21H2 + gitea-1.16.8-gogit-windows-4.0-amd64.exe
来做个实验, 来捋出解决问题的方法. 这样, 等gitea版本升级了, 也有一个通用的解决方案.
从网上资料看, gitea是有命令行的, 那试试命令行.
从gitea的github库下载的release, 只有一个exe, 我下载的是 gitea-1.16.8-gogit-windows-4.0-amd64.exe.
只要直接运行gitea-1.16.8-gogit-windows-4.0-amd64.exe, 啥都有了.
那来看看这个gitea-1.16.8-gogit-windows-4.0-amd64.exe有没有命令行.
C:\Users\xx>cd /d E:\git_rep_local
E:\git_rep_local>
E:\git_rep_local>gitea-1.16.8-gogit-windows-4.0-amd64.exe --help > help.txt
E:\git_rep_local>
NAME:
Gitea - A painless self-hosted Git service
USAGE:
gitea-1.16.8-gogit-windows-4.0-amd64.exe [global options] command [command options] [arguments...]
VERSION:
1.16.8 built with GNU Make 4.1, go1.18.2 : bindata, sqlite, sqlite_unlock_notify
DESCRIPTION:
By default, gitea will start serving using the webserver with no
arguments - which can alternatively be run by running the subcommand web.
COMMANDS:
web Start Gitea web server
serv This command should only be called by SSH shell
hook Delegate commands to corresponding Git hooks
dump Dump Gitea files and database
cert Generate self-signed certificate
admin Command line interface to perform common administrative operations
generate Command line interface for running generators
migrate Migrate the database
keys This command queries the Gitea database to get the authorized command for a given ssh key fingerprint
convert Convert the database
doctor Diagnose problems
manager Manage the running gitea process
embedded Extract embedded resources
migrate-storage Migrate the storage
docs Output CLI documentation
dump-repo Dump the repository from git/github/gitea/gitlab
restore-repo Restore the repository from disk
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--port value, -p value Temporary port number to prevent conflict (default: "3000")
--install-port value Temporary port number to run the install page on to prevent conflict (default: "3000")
--pid value, -P value Custom pid file path (default: "/run/gitea.pid")
--quiet, -q Only display Fatal logging errors until logging is set-up
--verbose Set initial logging to TRACE level until logging is properly set-up
--custom-path value, -C value Custom path file path (default: "E:/git_rep_local/custom")
--config value, -c value Custom configuration file path (default: "E:/git_rep_local/custom/conf/app.ini")
--version, -v print the version
--work-path value, -w value Set the gitea working path (default: "E:/git_rep_local")
--help, -h show help
DEFAULT CONFIGURATION:
CustomPath: E:/git_rep_local/custom
CustomConf: E:/git_rep_local/custom/conf/app.ini
AppPath: E:/git_rep_local/gitea-1.16.8-gogit-windows-4.0-amd64.exe
AppWorkPath: E:/git_rep_local
可以看到 admin 选项 是管理操作相关的
E:\git_rep_local>gitea-1.16.8-gogit-windows-4.0-amd64.exe admin --help > help.txt
E:\git_rep_local>
NAME:
Gitea admin - Command line interface to perform common administrative operations
USAGE:
Gitea admin command [command options] [arguments...]
COMMANDS:
user Modify users
repo-sync-releases Synchronize repository releases with tags
regenerate Regenerate specific files
auth Modify external auth providers
sendmail Send a message to all users
OPTIONS:
--custom-path value, -C value Custom path file path (default: "E:/git_rep_local/custom")
--config value, -c value Custom configuration file path (default: "E:/git_rep_local/custom/conf/app.ini")
--version, -v print the version
--work-path value, -w value Set the gitea working path (default: "E:/git_rep_local")
--help, -h show help
DEFAULT CONFIGURATION:
CustomPath: E:/git_rep_local/custom
CustomConf: E:/git_rep_local/custom/conf/app.ini
AppPath: E:/git_rep_local/gitea-1.16.8-gogit-windows-4.0-amd64.exe
AppWorkPath: E:/git_rep_local
可以看到 user 选项是修改用户信息的.
E:\git_rep_local>gitea-1.16.8-gogit-windows-4.0-amd64.exe admin user --help > help.txt
E:\git_rep_local>
NAME:
Gitea admin user - Modify users
USAGE:
Gitea admin user command [command options] [arguments...]
COMMANDS:
create Create a new user in database
list List users
change-password Change a user's password
delete Delete specific user by id, name or email
OPTIONS:
--custom-path value, -C value Custom path file path (default: "E:/git_rep_local/custom")
--config value, -c value Custom configuration file path (default: "E:/git_rep_local/custom/conf/app.ini")
--version, -v print the version
--work-path value, -w value Set the gitea working path (default: "E:/git_rep_local")
--help, -h show help
DEFAULT CONFIGURATION:
CustomPath: E:/git_rep_local/custom
CustomConf: E:/git_rep_local/custom/conf/app.ini
AppPath: E:/git_rep_local/gitea-1.16.8-gogit-windows-4.0-amd64.exe
AppWorkPath: E:/git_rep_local
可以看到, 已经到了用户操作的具体命令处了. 这里就大概知道咋干活了.
因为忘记了用户名, 先查看用户名列表. 尴尬啊…
E:\git_rep_local>gitea-1.16.8-gogit-windows-4.0-amd64.exe admin user list > help.txt
E:\git_rep_local>
ID Username Email IsActive IsAdmin
1 me me@me.com true true
可以看到, 我只给自己建立了一个用户, 这个用户名是me, 处于激活状态, 且是gitea管理员.
那现在就可以尝试重置me这个用户的口令, 然后用新口令登录, 就可以做所有事了.
E:\git_rep_local>gitea-1.16.8-gogit-windows-4.0-amd64.exe admin user change-password --help > help.txt
E:\git_rep_local>
NAME:
Gitea admin user change-password - Change a user's password
USAGE:
Gitea admin user change-password [command options] [arguments...]
OPTIONS:
--username value, -u value The user to change password for
--password value, -p value New password to set for user
--custom-path value, -C value Custom path file path (default: "E:/git_rep_local/custom")
--config value, -c value Custom configuration file path (default: "E:/git_rep_local/custom/conf/app.ini")
--version, -v print the version
--work-path value, -w value Set the gitea working path (default: "E:/git_rep_local")
DEFAULT CONFIGURATION:
CustomPath: E:/git_rep_local/custom
CustomConf: E:/git_rep_local/custom/conf/app.ini
AppPath: E:/git_rep_local/gitea-1.16.8-gogit-windows-4.0-amd64.exe
AppWorkPath: E:/git_rep_local
E:\git_rep_local>gitea-1.16.8-gogit-windows-4.0-amd64.exe admin user change-password -u me -p me > help.txt
E:\git_rep_local>
2022/05/20 09:46:53 main.go:117:main() [F] Failed to run app with [gitea-1.16.8-gogit-windows-4.0-amd64.exe admin user change-password -u me -p me]: Password is not long enough. Needs to be at least 6
可以看到, 口令没修改成功. 原因是口令长度最少要6个字符.
E:\git_rep_local>gitea-1.16.8-gogit-windows-4.0-amd64.exe admin user change-password -u me -p me1111 > help.txt
E:\git_rep_local>
me's password has been successfully updated!
可以看到, me用户的口令已经修改成功了.
运行本地git库目录下gitea-1.16.8-gogit-windows-4.0-amd64.exe.
在chrome浏览器中访问 http://localhost:3000
用list看到的管理员用户名登录, 输入自己改过的口令, 登录成功.
我就是发现push有问题, 才发现gitea.exe放错了位置, 进一步发现自己忘了用户名和口令.
现在重新push时, 因为用户名/口令已经重置了, 要重新输入用户名/口令, 输入改过的用户名/口令, 点击确定按钮.
看到git客户端显示push成功, gitea的命令行界面也提示操作成功.
问题解决.
这篇笔记分享了通用的gitea命令行用法, gitea升级了也不怕.
gitea还是挺好用的. 作者考虑的周全.
只要能物理接触到本地git库, 计算机的所有者当然有权限修改git库权限. gitea给的修改本地库口令功能是合理的.
自己本地不重要的git本地库, 可以尝试不断升级到最新的git库工具版本.
遇到问题, 总有解决的方法. 即使解决不了, 也有变通的方法, 损失都是可以接受的.
正式的git库相关工具配置是不能随便升级的.而且要定期做git库备份, 安全第一
今天手欠, 看到有新版gitea-1.17.1, 顺手就更新了.
尝试去登录 http://localhost:3000 , 忘记用户名了.
又从头看这篇笔记, 思路还是管用的, 思路没变.
尝试列出用户名列表
gitea-1.17.1-gogit-windows-4.0-amd64.exe admin user list
执行完后, 看到用户名后, 就想起自己的常用密码了.