How to change the last commit?

git commit --amend --no-edit

To change your last commit, start with adding your changes to the staging area with git add ..

Running git commit --amend --no-edit next will add your changes to the last commit without changing the commit message.

Layer 1
Terminal Example
git log --oneline
0c5fbac (HEAD -> main) Adding image.png and
9cfff18 Adding file.txt
git status
On branch main
Untracked files:
  (use "git add ..." to include in what will be committed)

nothing added to commit but untracked files present (use "git add" to track)
git add .
git commit --amend --no-edit
[main 16f0fe7] Adding image.png and
 Date: Sat May 15 15:24:48 2021 +0200
 2 files changed, 1 insertion(+)
 create mode 100644
 create mode 100644 image.png

See git commit to learn more about it.

Last modified on November 30, 2021.

You might also like