-
-
Notifications
You must be signed in to change notification settings - Fork 89
Command: git amend
Available since v0.3.8.
git amend
is used to amend the current commit and restack any descendant commits. It's a replacement for git commit --amend
.
Unlike git commit --amend
:
-
git amend
never updates the commit message, only the commit contents. -
git amend
automatically tries to restack any descendant commits. This is useful if you're modifying a commit which is earlier in a stack.
Make some changes:
$ echo 'Hello, world!' >>README.md
$ git status
On branch bug-report
Your branch and 'origin/bug-report' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
(You don't need to stage any changes.)
Then, to amend the current commit, run:
$ git amend
branchless: running command: git reset
Attempting rebase in-memory...
[1/1] Committed as: 89f87c23 temp: work on moving individual commits
branchless: processing 1 update: branch move-individual-commits
branchless: processing 1 rewritten commit
branchless: running command: git checkout bug-report
Switched to branch 'bug-report'
Your branch and 'origin/bug-report' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
branchless: processing checkout
In-memory rebase succeeded.
Finished restacking commits.
No abandoned branches to restack.
⋮
◇ 97f5fc72 2h (remote origin/master) docs: update CHANGELOG.md
┃
◯ 6372ca8e 54m feat(bug_report): create `bug-report` command
┃
● 933d2489 0s (ᐅ bug-report) feat(bug_report): use `bugreport` library to collect extra information
┃
◯ 89f87c23 0s (move-individual-commits) temp: work on moving individual commits
Amended with 1 uncommitted change.
Note that git amend
attempted to restack all descendant commits (and succeeded).
If you want to amend the current commit with only some changes, you can stage them first:
$ git add my-file
$ git amend # only updates with `my-file`
By doing this, git amend
knows to use the staged changes for the amend, and leaves the unstaged changes in place.
Available since v0.7.0.
Occasionally, you would like to make a change to a commit without rebasing the contents of the children commit. For example, if you run a formatter on your code, the result is likely to conflict with children commits, even though it will remain semantically the same. To amend a given commit while keeping the children commits exactly the same, run git amend
with the --reparent
option.
Note that this will cause the children commits to appear to "undo" all of the amended changes. You may want to follow up by manually editing the children commits.
See also git test fix
to automatically run commands like formatters and linters on a set of commits without risking merge conflicts.
- Search the Wiki 🔎
- User guide
- Welcome
- Installation
- Tutorial
- Command overview
- General:
- Navigation:
- Committing:
- Rebasing:
- Verification:
- Collaboration:
- Workflows
- Advanced topics
- Reference
- Developer guide
- Onboarding offer
- Development
- Reference