How do you change the last commit message or add a forgotten file?
BeginnerConceptCommits, branches and tags
Answer
Use git commit --amend. It replaces the last commit with a new one, so the ID changes. Only do this if the commit has not been shared, or be ready to force-push with lease.
git add forgotten.txt
git commit --amend --no-edit
git commit --amend -m "better message"
More on Commits, branches and tags
How do you write a good commit message?BeginnerWhat is the difference between `git add .`, `git add -A` and `git add -u`?BeginnerHow do you commit only part of the changes in a file?BeginnerWhat is the difference between `git switch`, `git restore` and `git checkout`?BeginnerWhat is the difference between lightweight and annotated tags?BeginnerHow does `git describe` work and where is it useful?Intermediate