machineghost
machineghost

Reputation: 35730

Why do I get an error when I try to git commit --amend

I wanted to modify the commit message on a commit I just made, so I tried to do:

git commit --amend

(as I normally do), but I got an error:

Unable to find modified files; please check git status

Now this is strange, because I'm not trying to add/remove files from the commit, I just want to change the message, so it shouldn't matter whether I have modified files or not.

Can anyone explain this error message (and ideally, how I can get past it)?

* EDIT *

Mellowcandle requested my git status; here it is (more or less):

# On branch some_branch
# Your branch is ahead of 'origin/some_branch' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   static/js/someFile.js
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   some/other/file
#   yet/another/file

* EDIT #2 *

The same problem occurs when I try to git rebase -i (with reword).

* EDIT #3 *

Here's the output of a git config --list (slightly anonymized), as requested by GoZoner:

user.name=My Name
[email protected]
push.default=upstream
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
[email protected]:someGitHubAccount/Apps.git
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.deploy.remote=origin
branch.deploy.merge=refs/heads/deploy
...*more branches that look similar*

Upvotes: 0

Views: 4000

Answers (6)

LeGEC
LeGEC

Reputation: 51780

Check if you don't have a custom hook which triggers on commit.

Upvotes: 2

GoZoner
GoZoner

Reputation: 70135

Works for me, both with and without modified, untracked files.

$ echo 'a' > a; git add -A; git commit -m 'a'
$ echo 'b' > b; git add -A; git commit -m 'b'

$ git log --oneline
63f2dd1 b
a0b364a a
$ git commit --amend
$ git log --oneline
d4cdeb7 bxx            # changed the commit message
a0b364a a

$ ed a # edit 'a'
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   a
#
no changes added to commit (use "git add" and/or "git commit -a")

$ git commit --amend
$ git log --oneline
2d20e6e bxxyy           # changed the commit message again
a0b364a a

$ mkdir foo; echo 'c' > foo/c
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   a
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   foo/
no changes added to commit (use "git add" and/or "git commit -a")

$ git commit --amend
ebg@ebg(31)$ git log --oneline
09c1b26 bxxyyzz
a0b364a a

Upvotes: 1

stdcall
stdcall

Reputation: 28860

Do git stash. Then do git commit --amend. After that do git stash pop.

Upvotes: 1

Abizern
Abizern

Reputation: 150565

Alternatively, you could just do an interactive rebase on the parent of the current commit

git rebase -i head~

And then choose the reword option to change the commit message.

Upvotes: 2

hobbs
hobbs

Reputation: 239652

Try git commit --amend --only, and if that doesn't work then just try git stash; git commit --amend ; git stash pop. I'm not sure what state you're in here.

Upvotes: 1

poke
poke

Reputation: 387507

git commit --amend will work just like git commit just that it will recycle your old commit. So what this means is that it will expect that there are actually some changes in the index, ready to be committed.

So, if you want your someFile.js to be included, run git add static/js/someFile.js first. If you also want to track that untracked file, add that too using git add some/other/file.

Upvotes: 1

Related Questions