0

我想修改我刚刚提交的提交消息,所以我尝试这样做:

git commit --amend

(就像我通常做的那样),但我得到了一个错误:

Unable to find modified files; please check git status

现在这很奇怪,因为我不是试图从提交中添加/删除文件,我只是想更改消息,所以我是否修改了文件并不重要。

任何人都可以解释这个错误信息(理想情况下,我怎样才能克服它)?

* 编辑 *

Mellowcandle 请求了我的 git 状态;这是(或多或少):

# 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

* 编辑 #2 *

当我尝试git rebase -i(with reword) 时也会出现同样的问题。

* 编辑 #3 *

这是git config --listGoZoner 要求的(略微匿名)的输出:

user.name=My Name
user.email=email@example.com
push.default=upstream
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=git@github.com: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*
4

6 回答 6

2

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

于 2013-04-25T07:05:59.340 回答
2

或者,您可以只对当前提交的父级进行交互式变基

git rebase -i head~

然后选择reword更改提交消息的选项。

于 2013-02-27T18:19:53.650 回答
1

git commit --amend就像git commit它会回收你的旧提交一样工作。所以这意味着它会期望索引中实际上有一些更改,准备好提交。

所以,如果你想让你someFile.js被包括在内,git add static/js/someFile.js首先运行。如果您还想跟踪该未跟踪的文件,也可以使用git add some/other/file.

于 2013-02-27T18:10:19.713 回答
1

试一试git commit --amend --only,如果这不起作用,那就试一试git stash; git commit --amend ; git stash pop。我不确定你在这里处于什么状态。

于 2013-02-27T18:13:12.633 回答
1

git stash。然后做git commit --amend。之后做git stash pop

于 2013-02-27T18:32:19.527 回答
1

对我有用,无论有没有修改的、未跟踪的文件。

$ 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
于 2013-04-23T21:53:52.057 回答