Amend
一句话解释
Amending 修改最后提交 — 它能 添加 forgotten 更改 or 更改提交消息不使用创建新 提交.
用大白话说
git commit --amend modifies the most recent commit instead of creating a new one. It is useful for two scenarios: (1) you forgot to stage a file and want to add it to the last commit, and (2) you want to fix a typo in the last commit message.
Amend creates a new commit with a new hash that replaces the old one. The old commit becomes unreachable. This is fine if you have not pushed the commit yet. If you have already pushed, you must force-push to update the remote, which can cause problems for others.
Common usage: git 添加 forgotten-file.js && git 提交 --amend --否-编辑 adds a file to the last commit without changing the message. git 提交 --amend -m "新消息" changes only the message. Never amend commits that have been pushed to shared branches.
示例
# Add a forgotten file to the last commit
git add forgotten.js
git commit --amend --no-edit
# Change the last commit message
git commit --amend -m "Better commit message"amend 修改最后提交. 做不 amend pushed 提交.
相关术语
相关资源
相关课程
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。