没有不值得去解决的问题,也没有不值得去学习的技术!

Modify a Committed GitLab Message in Git

Use the push --force-with-lease command to force push the modified old commit

1. Now that the commit has been pushed to GitLab.com, you must force push the commit with the corrected message. The commit message does not comply with Conventional Commits, found at: https://www.conventionalcommits.org/zh-hans/v1.0.0/

2. Reference: https://docs.github.com/cn/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/changing-a-commit-message .

3. Use the git commit –amend command to modify the commit message. Type git commit –amend, then press Enter. Enter your modified commit message. Lines
starting with ‘#’ will be ignored.

4. Edit the commit message in the text editor, then save the commit. See Figure 1.

Edit the commit message in the text editor, then save the commit
Figure 1

5. Use the push –force-with-lease command to force push the modified old commit. See Figure 2.

Use the push --force-with-lease command to force push the modified old commit
Figure 2
Plaintext

PS E:\wwwroot\object> git push --force-with-lease origin example-branch    Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 4 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.59 KiB | 108.00 KiB/s, done.
Total 10 (delta 8), reused 0 (delta 0), pack-reused 0
remote:
remote: View merge request for example-branch:
remote:   https://xxx/themes/object/-/merge_requests/487
remote:
To https://xxx/themes/object.git
 + efb465f5...61478100 example-branch -> example-branch (forced update)
PS E:\wwwroot\object>

6. View the commit message on GitLab; the feat: prefix has been added. See Figure 3.

View the commit message on GitLab; the feat: prefix has been added
Figure 3

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系