Gitチュートリアル


Gitと{{title}}


Gitの貢献


Git Advanced


Git Undo




Git Amend


Git commit --amend

commit --amend最新のを変更するために使用されcommitます。

staging environmentの変更と最新の変更を組み合わせてcommit、新しいを作成し commitます。

この新しいものは、最新のものを完全にcommit置き換え ます。commit


Git AmendCommitメッセージ

できる最も簡単なことの1つは、メッセージ--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 w3schools-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/w3schools-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 w3schools-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/w3schools-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コミットする前にそれらを追加するだけ です。


エクササイズで自分をテストする

エクササイズ:

commitのをメッセージで修正します"Updated index"

git    ""