Undo a commit
Wechseln Sie in das Verzeichnis git-tutorial/tutorial2, das Sie zuvor heruntergeladen haben.
Wenn Sie den Verlauf dieses Repositorys untersuchen, sieht er wie folgt aus:
Wir werden den Commit „append description of the pull command“ mit dem Befehl git revert rückgängig machen.
Öffnen Sie zunächst die Datei sample.txt, und überprüfen Sie, ob ihr Inhalt wie folgt aussieht:
Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
commit: Save the status of an index
pull: Obtain the content of the remote repository
Wir werden den letzten HEAD-Commit mit dem Namen „append description of the pull command“ mit dem revert-Befehl auf folgende Weise rückgängig machen.
$ git revert HEAD
[main d47bb1d] Revert "append description of the pull command"
1 files changed, 1 insertions(+), 2 deletions(-)
Wenn wir nun sample.txt öffnen, werden Sie sehen, dass die letzte Zeile (d. h. „pull: Obtain the content of the remote repository“) nicht mehr existiert.
Verwenden Sie den Befehl git log, um zu überprüfen, ob der neue Verlauf wie folgt aussieht:
$ git log
commit 7bcf5e3b6fc47e875ec226ce2b13a53df73cf626
Author: yourname <yourname@yourmail.com>
Date: Wed Jul 18 15:46:28 2022 +0900
Revert "append description of the pull command"
This reverts commit 0d4a808c26908cd5fe4b6294a00150342d1a58be.
commit 0d4a808c26908cd5fe4b6294a00150342d1a58be
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:19:26 2022 +0900
append description of the pull command
commit 9a54fd4dd22dbe22dd966581bc78e83f16cee1d7
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:19:01 2022 +0900
append description of the commit command
commit 326fc9f70d022afdd31b0072dbbae003783d77ed
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:17:56 2022 +0900
append description of the add command
commit 48eec1ddf73a7fb508ef664efd6b3d873631742f
Author: yourname <yourname@yourmail.com>
Date: Mon Jul 16 23:16:14 2022 +0900
first commit