git 修正
Git 提交--修改
commit --amend
用于修改最近的commit
。
它结合了staging environment
与最新的commit
,并创建一个新的commit
。
这个新的commit
替换最新的commit
完全。
Git 修改提交消息
您可以做的最简单的事情之一--amend
就是改变一个commit
信息。
让我们更新一下README.md
和commit
:
示例
git commit -m "Adding plines to reddme"
[master 07c5bc5] Adding plines to reddme
1 file changed, 3 insertions(+), 1 deletion(-)
现在让我们检查一下log
:
示例
git log --oneline
07c5bc5 (HEAD -> master) Adding plines to reddme
9a9add8 (origin/master) Added .gitignore
81912ba Corrected spelling error
3fdaa5b Merge pull request #1 from 91xjr-test/update-readme
836e5bf (origin/update-readme, update-readme) Updated readme for GitHub Branches
daf4f7c (origin/html-skeleton, html-skeleton) Updated index.html with basic meta
facaeae (gh-page/master) Merge branch 'master' of https://github.com/91xjr-test/hello-world
e7de78f Updated index.html. Resized image
5a04b6f Updated README.md with a line about focus
d29d69f Updated README.md with a line about GitHub
e0b6038 merged with hello-world-images after fixing conflicts
1f1584e added new image
dfa79db updated index.html with emergency fix
0312c55 Added image to Hello World
09f4acd Updated index.html with a new line
221ec6e First release of Hello World!
不好了!这commit
消息充满拼写错误。尴尬。让我们amend
那:
示例
git commit --amend -m "Added lines to README.md"
[master eaa69ce] Added lines to README.md
Date: Thu Apr 22 12:18:52 2021 +0200
1 file changed, 3 insertions(+), 1 deletion(-))
并重新检查log
:
示例
git log --oneline
eaa69ce (HEAD -> master) Added lines to README.md
9a9add8 (origin/master) Added .gitignore
81912ba Corrected spelling error
3fdaa5b Merge pull request #1 from 91xjr-test/update-readme
836e5bf (origin/update-readme, update-readme) Updated readme for GitHub Branches
daf4f7c (origin/html-skeleton, html-skeleton) Updated index.html with basic meta
facaeae (gh-page/master) Merge branch 'master' of https://github.com/91xjr-test/hello-world
e7de78f Updated index.html. Resized image
5a04b6f Updated README.md with a line about focus
d29d69f Updated README.md with a line about GitHub
e0b6038 merged with hello-world-images after fixing conflicts
1f1584e added new image
dfa79db updated index.html with emergency fix
0312c55 Added image to Hello World
09f4acd Updated index.html with a new line
221ec6e First release of Hello World!
我们看到前面的commit
已替换为我们修改后的版本!
警告:搞乱commit
存储库的历史记录可能很危险。通常可以对您自己的本地存储库进行此类更改。但是,您应该避免进行重写历史记录的更改remote
存储库,特别是当其他人正在使用它们时。
Git 修改文件
添加文件--amend
工作方式与上面相同。只需将它们添加到staging environment
在提交之前。